Primary Category 2.x

Legacy documentation for Primary Category 2.x.

The Primary_Category tag allows you to parse the category variables for each primary category, as well as providing more flexibility (over using the variables approach in the Channel:Entries tag).

{exp:primary_category} content {/exp:primary_category} 

Parameters

The following parameter is available for use:

category_group=

category_group="3" 

This parameter allows you to filter your primary category results down to a specific category group.

entry_id=

entry_id="{segment_3}" 

This parameter is used for displaying data for a specific weblog entry. You can hardcode an entry ID, pass it through an embed, grab it from the URI, or parse the {entry_id} variable through the Channel:Entries tag. This tag is also capable of just dynamically reading an entry ID or URL title from the URI.

Variables

The following variables are available for use:

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:

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. {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 title and body field, as well as the Primary Category image and Primary Category name linked to a template that will show entries asigned to that same category. In the scenario below, this code would be displayed on a single entry page, where the exp:primary_category tag would detect the entry ID or URL title in the URL.

{exp:channel:entries
    require_entry="yes"
}
    <h3>{title}</h3>
    <p>{body}</p>
{/exp:channel:entries}

{exp:primary_category
    entry_id="{segment_3}"
}
    <p>
        <img src="{primary_category_image}" />
        <a href="{path='articles/category'}/{primary_category_url_title}/">{primary_category_name}</a>
    </p>
{/exp:primary_category}