Forums

List Subcategories of Parent Category (3 posts)

  1. zerovic
    Member
    Posted 1 year ago #

    hey guys,

    here's my problem..
    i have added 5 parent categories with like 5subcategories under each
    example
    -Products
    --TV
    --RADIO
    --GAMES
    etc

    what i want is to get the level 2 categories to be displayed under the category listing page. it's kinda easy, since i have done this a few weeks ago, but anytime i click on a subcategory, the list gets empty, since it tries to pull out the subcategories of the subcategories again.

    so, here's what i want
    i want to get a static level 2 category list to be displayed only. so, when i click products, i want to see the subcategories only, if i click a subcategory, i want to get the same list as before.

    any help appreciated!

    kind regards,
    zerovic

  2. zerovic
    Member
    Posted 1 year ago #

    ok well, i couldn't sleep last night, so i have played around with the codes ;)
    here's the solution!

    <h4>Categories</h4>
    <ul class='xoxo blogroll'>

  3. <?php
    $parentCatList = get_category_parents($cat,false,',');
    $parentCatListArray = split(",",$parentCatList);
    $topParentName = $parentCatListArray[0];
    $id = get_cat_id($topParentName);
    wp_list_cats('sort_column=id&optioncount=0&use_desc_for_title=0&child_of=' . $id);
    ?>
  4. kind ragards,
    zerovic

  5. bevi
    Member
    Posted 1 year ago #

    zerovic you're great!!! solve my issue about show posts in child cats calling from parent cat ID.
    if any one looking that I let the code I use.

    <?php
    $temp = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
    $parentCatList = get_category_parents($cat,false,',');
    $parentCatListArray = split(",",$parentCatList);
    $topParentName = $parentCatListArray[0];
    $id = get_cat_id($topParentName);
    $wp_query->query('cat='.$id.'&order=ASC');
    ?>
    
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    
    //Stuff
    
    <?php endwhile; ?>
    
    <?php $wp_query = null; $wp_query = $temp;?>

    That´s it, beautiful!
    Cya

Topic Closed

This topic has been closed to new replies.

About this Topic