Forums

Seperate template for each catergory - display only child catergory on page (3 posts)

  1. babypress
    Member
    Posted 2 years ago #

    This is what I want to do: (found it on wordpress site but was for pages not categories, I just changed it around as it is what im looking for)

    Example – lets say this is my site map (* = category page | o = sub category) .

    * Africa
    o Cameroon
    o Lesotho
    o Swaziland
    o Togo
    * South America
    o Argentina
    o Brazil

    When you are on the Africa category, Cameroon, Lesotho, Swaziland, or Togo page -you see the child/sub category links for Africa only and not South America

    Like wise If you were on the South America, Argentina or Brazil category you would only see the sub category pages for South America and not the sub category pages for Africa nor the Africa page.

    I understand that I need to make separate category template files eg category-2.php category-3.php? bu how to have their sub categories show too?

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    Not sure that this is what you are asking for...could put this in your sidebar.php

    <?php
    //If category archive show chidren in sidebar.php
    if (is_category( )) {
      $cat = get_query_var('cat');
      $parent = get_category ($cat);
      if ($parent->parent) {
        wp_list_categories ('child_of=' . $parent->parent);
        } else {
        wp_list_categories ('child_of=' . $cat);
      }
    }
    ?>

    Related:
    Template Tags wp_list_categories()
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

  3. babypress
    Member
    Posted 2 years ago #

    Hi MichaelH,

    I will give it a try, Im not so familiar with writing php but will test your recommendation to see if it turns out what I need and thanks for the links for further reading, will do.

Topic Closed

This topic has been closed to new replies.

About this Topic