WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Child categories display only?? (5 posts)

  1. jarvis88
    Member
    Posted 5 years ago #

    Hi...

    I have searched the forums and it just seems nothing helps! So someone please help!! I have a bunch of caregories with children, grand children, and even more grand children.

    I have used a plugin to stop a child categories' posts to display in its parent category aswell. Which works fine...

    But now the parent category is empty and contains no information. So I would like to display the current categories children on the page. I dont have a category.php so my archive.php is being used for the display of categories.

    I have tried using this...

    <?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);
    						   }
    				}
    			?>

    but it only displays that current categories title and link!

    Please help!!

    Pleeeeeeeeeeeeaaase!!!!

  2. jarvis88
    Member
    Posted 5 years ago #

    Sorry to bump this guys.... But I really need help with this!! Its a matter of life and death!!

    Any help much appreciated!!

  3. jarvis88
    Member
    Posted 5 years ago #

    Okey, somehow I missed this in the codex!

    Only Show Children of a Category

    The following example code generates category links, sorted by ID, only for the children of the category with ID 8; it shows the number of posts per category and hides category descriptions from the title attribute of the generated links. Note: If there are no posts in a parent Category, the parent Category will not display.

    <ul>
    <?php wp_list_categories('orderby=id&amp;show_count=1
    &amp;use_desc_for_title=0&amp;child_of=8'); ?>
    </ul>

    The only problem is that if there is no posts in a category it will not display the children of that category as stated in the above codex paragraph...

    Some of my categories are there only for navigation and has no need to contain posts, just its children which in return has posts.

    The reason I want the empty parent category to display its children is so that a user doesnt end up clicking on that parent and finds no content. So by displaying its children I provide a kind of index to that parent!

    Please help someone!!
    I don't like talking to myself here.... LOL!!

  4. jarvis88
    Member
    Posted 5 years ago #

    this is why I say never give up! Solved the problem myself!!!!

    This is what I did if anyone wants to know for future reference...

    <div class="center-cat"><!--display child cats-->
    
    <ul>
    <?php if (is_category('3')) { wp_list_categories('orderby=id&amp;show_count=1&amp;title_li=&amp;use_desc_for_title=0&amp;child_of=3'); } ?>
    </ul>
    
    </div>

    Okey, the '3' is my category number... the 'if is category' is there so that the childs of cat 3 will only display on the '3' category and not on any of the other categories...

    the rest of the parameters is difined in the codex... look there..

    paste the code in the php template file that the categories are displaying on (eg, category.php or archive.php) and make sure you paste it outside the loop... else your category would need a post to display the code you pasted...

    hope this helps someone....

    Thanks for helping forum....

  5. cornhustlah
    Member
    Posted 4 years ago #

    AWSM.

    thank you thank you thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic