User Documentation

Assigning Users to Categories

The User Categories feature allows your users to assign themselves to regular EE categories. It basically allows you to create a way to group or tag your members, and even go as far as turning channel entry content as subscribe-able for users (they can filter the entries they see based on which EE categories they have assigned to them). All of this happens on the front end in EE templates. To enable this feature, go to the Preferences page in the User area of the EE control panel and select the category group(s) you'd like User to use. There is support for User Categories across all of the applicable User template tags:

User:Profile

The User Categories feature in the User:Profile tag allows you to display categories that are currently assigned to the current member or member profile being viewed.

The following parameters are available for use with this tag:

member_only="no"

Normally only categories assigned to the user would be shown here. But specify this parameter (on the User:Profile tag) with a value of no and it will show ALL categories available for User. Default is yes, and you can most often just not specify this parameter altogether.

parent_id="4"

In the event you're using a mix of sub-categories and parent categories for your users to assign themselves to, you can specify this parameter (on the User:Profile tag) to filter down to the parent category so that the categories variable pair does not output the parent and child category.

The following variable pair is available for use with this tag:

{categories backspace="2"}
    {category_body}<a href="{path='user/memberlist/category'}/{category_url_title}">{category_name}</a>, {/category_body}
{/categories}

This variable pair allows you to display the category a user has assigned themselves to.

Here's what an example of this code in action might look like:

{exp:user:profile
    parent_id="3"
}
    <h3>Screen Name: {screen_name}</h3>
    <p>Location: {location}</p>
    <p>Join Date: {join_date format="%F %j, %Y"}</p>
    <p>
        Currently assigned to the following categories:
        {categories backspace="2"}
            {category_body}{category_name}, {/category_body}
        {/categories}
    </p>
{/exp:user:profile}

User:Users

The User Categories feature in the User:Users tag allows you to filter the list of users by ones that have that specified category.

The following parameters are available for use with this tag:

category="56"

Filter the list of users by a category ID or URL title. Any users that have that category assigned to them should show in the results. The User:Users function also has dynamic recognition of a category ID or URL title specified in the URL.

The following variable pair is available for use with this tag:

{categories backspace="2"}
    {category_body}<a href="{path='user/memberlist/category'}/{category_url_title}">{category_name}</a>, {/category_body}
{/categories}

This variable pair allows you to display which categories each user has assigned themselves to.

Here's what an example of this code in action might look like:

<ul>
{exp:user:users
    category="56"
    orderby="screen_name" sort="asc"
    limit="25"
    paginate="both"
}
    <li>
        <a href="{path='users/profile'}/{member_id}">{screen_name}</a>
        (Categories:
        {categories backspace="2"}
            {category_body}{category_name}, {/category_body}
        {/categories})
    </p>
    </li>
    {if user_no_results}
        <li>
            Sorry, no results were found.
        </li>
    {/if}
    {user_paginate}
        <li>
            Page {user_current_page} of {user_total_pages} pages
            {user_pagination_links}
        </li>
    {/user_paginate}
{/exp:user:users}
</ul>

User:Search

The User Categories feature in the User:Search tag allows you to search on a category when performing a user search.

The following parameters are available for use with this tag:

inclusive_categories="yes"

When someone searches and provides more than one category, specifying a value of yes for this parameter means that all provided categories must match for a user to be returned.

The following variables are available for use with this tag:

{user_category}

This variable returns the User Category that was searched upon previously. This would be used if you were using the User:Search function to search within search results.

{user_parent_category}

This variable returns the parent User Category that was searched upon previously. This would be used if you were using the User:Search function to search within search results.

The following form field is available for use with this tag:

<input name="category[]" />

This field allows you to provide one or more category ID's in the search form fields.

Here's what an example of this code in action might look like:

{exp:user:search
    return="user/results"
}
    <h2>Search Members</h2>
    <p>Keywords: <input type="text" name="keywords" /></p>
    <p>
        Category:
        <label>
            <input type="checkbox" name="category[]" value="54" />
            Monkey
        </label>
        <label>
            <input type="checkbox" name="category[]" value="23" />
            Pie
        </label>
        <label>
            <input type="checkbox" name="category[]" value="17" />
            Cheese Burgers
        </label>
    </p>
    <p><button type="submit">Search</button></p>
{/exp:user:search}

User:Edit & User:Register

The User Categories feature in the User:Edit and User:Register tags allows your users to add/remove categories to themselves during profile edit or registration. The variable pairs below are the same for both tags with the exception of the category_selected, since a new registration would not have any previously selected category data. NOTE: Any Categories previously assigned to a user will be lost if any User:Edit forms are submitted and do not contain code for the User Category feature. To get around this if you have split your form into multiple forms/pages, be sure to include a hidden field for the Categories. See this example for more information.

The following parameter is available for use with this tag:

parent_id="4"

Using the User Category feature, in the event you're using sub-categories or a parent category for your users to assign themselves to, you can specify the parent_id parameter to filter down to the parent category so that the Categories variable pair does not output the parent and child category.

The following variable pairs are available for use with this tag:

{categories orderby="category_order"}{/categories}

This variable pair allows you or your members to assign themselves to regular EE categories. It is a very powerful and flexible function as it contains several variable pairs within for construct of detailed select form fields. This is great to use as an additional way of sorting and filtering your users and channel entries for your users based on the Category they're assigned to. See code examples.

Available parameters for this variable pair are:

  • group_id="" - specify the category group ID's you want displayed.
  • orderby="" - order the categories by order in CP, or alphabetically.
  • site_id="" - specify the category groups from the MSM sites you want displayed.

{category_group_header}{/category_group_header}

This variable pair parses out its contents at the top of the resulting category list. Placed inside the categories variable pair.

{category_group_footer}{/category_group_footer}

This variable pair parses out its contents at the bottom of the resulting category list. Placed inside the categories variable pair.

{category_indent}{/category_indent}

This variable pair allows you to place an indentation on child categories in the category list. The contents of this variable pair are parsed with the {indent} variable inside of the category_body variable pair where you expect the indentation to appear. When you have nested categories, the contents of the indent pair precede the category block. Placed inside the categories variable pair.

{category_body}{/category_body}

This variable pair parses out the main contents of the category list. Within this variable pair, you can place the {indent} and {selected} variables, which get parsed with the contents of what you specify in the related variable pairs. Placed inside the categories variable pair.

{category_selected}{/category_selected}

This variable pair allows you to place a selected attribute to your categories list field (could be selected, checked, etc, depending on your form field type). The contents of this variable pair are parsed with the {selected} variable inside of the category_body variable pair. Placed inside the categories variable pair.

Here are some examples of this code in action might look like:

Select Menu Example

<select name="category[]">
{categories}
    {category_selected}selected="selected"{/category_selected}
    {category_indent}-{/category_indent}
    {category_body}
        <option value="{category_id}" {selected}>
            {indent}{category_name}
        </option>
    {/category_body}
{/categories}
</select>

Checkbox Example

{categories}
    {category_selected}checked="checked"{/category_selected}
    {category_body}
        <input type="checkbox" name="category[]"
        value="{category_id}" {selected} /> {category_name}
    {/category_body}
{/categories}

Multi-Select Menu with Multiple Category Groups Example

<select name="category[]" multiple="multiple">
    {categories group_id="1|4"}
        {category_group_header}
            <optgroup label="{category_group_name}">
        {/category_group_header}
        {category_selected}selected="selected"{/category_selected}
        {category_indent}-{/category_indent}
        {category_body}
            <option value="{category_id}" {selected}>
                {indent}{category_name}
            </option>
        {/category_body}
        {category_group_footer}
            </optgroup>
        {/category_group_footer}
    {/categories}
</select>

Separate Select Menus for each Category Groups Example

{categories group_id="1|4"}
    {category_group_header}
        <select name="category[]" multiple="multiple">
    {/category_group_header}
    {category_selected}selected="selected"{/category_selected}
    {category_indent}-{/category_indent}
    {category_body}
        <option value="{category_id}" {selected}>
            {indent}{category_name} - {category_group_name}
        </option>
    {/category_body}
    {category_group_footer}
        </select>
    {/category_group_footer}
{/categories}

Hidden Category field to Prevent Category Data Loss Example

Basically, if you have any User:Edit forms that do NOT contain a Category field (with populated category data), when that form is submitted, all User Category data for that member will be deleted. To circumvent this, you can add a hidden category field in your Edit forms (that do not contain a visible Category field):

{categories}
    {category_selected}
        <input type="hidden" name="category[]" value="{category_id}" />
    {/category_selected}
    {category_body}
        {selected}
    {/category_body}
{/categories}

Support

Having problems setting up and/or using User? Support is offered from 10am to 4pm EST weekdays. Send us an email at help@eeharbor.com and we will respond as quickly as we can.