• Hello

    I want to add multi-level categories in my wp theme. First, there should be categories. And I want to add sub-categories in them. And in the sub categories my posts should be shown.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Categories are multi-level by default. Even if your theme does not display them as levels, the capability should be there. Changing the template to display different levels may be all that’s needed.

    When posts are queried by a category term, it doesn’t matter what level the term resides on, posts either are associated with the term or they are not.

    If you are registering other taxonomies pass the 'hierarchical' => true argument to register_taxonomy()

    Thread Starter Muhammad Rizwan

    (@rizwan_47)

    I know categories are multi-level by default. But the thing is I have to display course categories->courses->lessons.

    On the first page all the course categories will be displayed when you click it, it goes to it’s courses, and when I click on any course I’ll be redirected to it’s lessons. And on lessons posting the_permalink will be called to redirect to lessons’s content.

    Moderator bcworkz

    (@bcworkz)

    Ah! Thanks for clarifying, that makes much more sense.

    There’s a number of approaches, depending on what user experience you intend. It could be a series of simple templates, a single complex template, or some combination. Some or all portions could rely on AJAX calls, or could be done completely with permalinks or URL parameters. If the number of terms are not huge, much of the content can be on a single page, the appropriate portions revealed or hidden with javascript or jQuery.

    All approaches would revolve around using get_categories() to retrieve each level in turn. On the final category level that would lead to a list of posts, it may be easier to use wp_list_categories() instead.

    If you may need to use categories for other posts unrelated to lessons, consider creating a custom taxonomy for the course/lesson structure. There are parallel functions to the ones mentioned for categories for taxonomies.

    Not required, but nice to have is a permalink structure that mirrors the path through the levels. Doing so requires the use of the Rewrite API.

    Thread Starter Muhammad Rizwan

    (@rizwan_47)

    Thanks for the guidance. I got it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add multi-level categories/taxonomies on one post type’ is closed to new replies.