Primary Category 2.x

Legacy documentation for Primary Category 2.x.

While support for Channel Form is limited, Primary Category does work with Channel Form in the simplest form.

By specifying a form field with the name of primary_category, you can add, update or remove a primary category. The field looks for a pipe delimited list of category ID's (multiples allowed when using across different category groups).

A complete example of a Channel Form form would look like this:

<h1>Create a new Entry</h1>

{exp:channel:form
    channel="articles"
    return="articles/entry/URL_TITLE"
}
    <p>
        <label>Title:</label><br />
        <input type="text" name="title" size="80" style="width: 600px;" />
    </p>
    <p>
        <label>Body:</label><br />
        <textarea name="body" style="width: 600px; height: 50px;" /></textarea>
    </p>
    <p>
        <label>Categories:</label><br />
        <select name="category[]" size="4" multiple="multiple">
        {categories}
            <option value="{category_id}" {selected}>
                {category_name}
            </option>
        {/categories}
        </select>
    </p>
    <p>
        <label>Primary Category:</label><br />
        <select name="primary_category">
        {categories}
            <option value="{category_id}"{exp:primary_category entry_id="{entry_id}"}{if '{category_id}' == '{primary_category_id}'} selected="selected"{/if}{/exp:primary_category}>
                {category_name}
            </option>
        {/categories}
        </select>
    </p>
    <p>
        <input type="submit" name="submit" value="Update" />
    </p>

{if no_results}
    <p>No Results</p>
{/if}

{/exp:channel:form}