Primary Category 2.x

Legacy documentation for Primary Category 2.x.

Primary Category allows you to call Primary Category variables (within the primary_categories variable pair) like normal EE variables in your Channel:Entries tags. Alternately, you can use the Primary_Category tag instead.

{exp:channel:entries} content {/exp:channel:entries} 

Parameters

The following parameters are available for use:

category_group=

category_group="3" 

This parameter allows you to filter your primary category results down to a specific category group. This parameter is applied to the primary_categories variable pair.

disable=

disable="custom_fields|primary_category" 

To eliminate extra unnecessary queries, you can specify primary_category in the Channel:Entries tag disable parameter. You would typically use this on templates where are not running any Primary Category data.

Variables

The following variables are available for use within the {primary_categories}{/primary_categories} variable pair:

primary_category_id

{primary_category_id} 

Displays the category ID of the primary category.

primary_category_name

{primary_category_name} 

Displays the category name of the primary category.

primary_category_url_title

{primary_category_url_title} 

Displays the category URL title of the primary category.

primary_category_description

{primary_category_description} 

Displays the category description of the primary category.

primary_category_image

{primary_category_image} 

Displays the category image of the primary category.

primary_category_CUSTOM_CATEGORY_FIELD

{primary_category_CUSTOM_CATEGORY_FIELD} 

Displays any category custom field of the primary category. When building the variable, start with primary_category_ and finish with the name of the custom field (ex: {primary_category_my_field}).

primary_category_group_id

{primary_category_group_id} 

Displays the category group ID of the primary category.

primary_category_group_name

{primary_category_group_name} 

Displays the category group name for the primary category.

primary_category_order

{primary_category_order} 

Displays the category order of the primary category.

primary_category_parent_id

{primary_category_parent_id} 

Displays the category parent ID of the primary category.

primary_category_parent_name

{primary_category_parent_name} 

Displays the category parent name of the primary category.

primary_category_parent_url_title

{primary_category_parent_url_title} 

Displays the category parent URL title of the primary category.

Variable Pairs

The following variable pair is available for use:

primary_categories

<ul>
{primary_categories}
    <li>{primary_category_name}</li>
{/primary_categories}
</ul>

This variable pair is used to loop through each primary category and parse its variables. If you have more than one primary category, this allows you to handle the formatting for each instance.

select_CUSTOM_CATEGORY_FIELD

<select name="CUSTOM_CATEGORY_FIELD">
    {select_CUSTOM_CATEGORY_FIELD}
    <option value="{value}" {selected}>
        {value}
    </option>
    {/select_CUSTOM_CATEGORY_FIELD}
</select>

If a custom category field is a drop-down list, you can parse it as a drop-down list with the select_ construct as seen above. To be used within the {primary_categories}{/primary_categories} variable pair. {selected} is typically used for radio buttons or select fields, whereas {checked} is used for checkboxes.

Conditionals

Conditionals can be run on all of the Primary Category variables. Additionally, the following conditional is available for use:

if primary_category_no_results

{if primary_category_no_results}
    No primary categories for this entry.
{/if}

You can use this conditional to display alternate content if there are no primary category results found for the entry.

Examples

The below example shows the channel entry titles and body fields, as well as the Primary Category image and Primary Category name linked to a template that will show entries asigned to that same category.

{exp:channel:entries}
    <h3>{title}</h3>
    <p>{body}</p>

    <ul>
    {primary_categories}
        <li>
            <img src="{primary_category_image}" />
            <a href="{path='articles/category'}/{primary_category_url_title}/">
                {primary_category_name}
            </a>
        </li>
    {if primary_category_no_results}
        <li>No primary categories for this entry.</li>
    {/if}
    {/primary_categories}
    </ul>

{/exp:channel:entries}