Ready to get started?Download WordPress


How to create a category template for each category hierarchy level? (2 posts)

  1. joaoramos
    Posted 1 year ago #

    Is it possible to create a category template for each of the available hierarchy levels? Here's the structure I want to replicate:

    • Product A (level 0)
      • Subproduct A1 (level 1)
      • Subproduct A2 (level 1)
      • Subproduct A3 (level 1)
    • Product B (level 0)
      • Subproduct B1 (level 1)
      • Subproduct B2 (level 1)
        • Sub-subproduct B2.1 (level 2)

    For each of three hierarchy levels above, I want to display the following data (possibly using a separate category file or page template for each of them):

    1. Current category ID;
    2. Current category name;
    3. Current category description;
    4. Related child and/or parent categories (when available), and loop them.

    How should I assign posts to their related categories (from different levels) to achieve this structure? Important update: I might be misunderstanding the whole relation between posts and categories. Perhaps I could achieve the same structure just by assigning one post per each category, from each hierarchy level? This way all category pages would display the data from the only category assigned to them, and could be styled using hierarchy level page templates. Does this make any sense?

  2. Bas Schuiling
    Posted 1 year ago #

    The last makes sense yes. Categories know their parents if defined well. So you could theme for that and display all the 'parent' categories in a sort of breadcrumb kind of way.

    Check out the category template functions on how to get parent categories and such.

Topic Closed

This topic has been closed to new replies.

About this Topic