WordPress.org

Forums

[resolved] wp_list_categories() not showing (6 posts)

  1. ryanbuckley
    Member
    Posted 1 year ago #

    I posted this to a previous topic I had made for a related issue, but perhaps this would be better placed here with a less ambiguous title, where others could benefit from the support for a more relevant issue:

    After searching the forums for a solution, I still cannot get wp_list_categories() to work.

    I have placed it before the loop, and even with categories for which I know there are posts, i still get "No categories".

    For example:
    http://www.be-hold.com/category/category
    is a parent category to
    http://www.be-hold.com/category/category/contemporary-color
    which, as you can see, does contain posts

    Here is a snip-it of code from my Categories page. The page loads posts if the visitor is viewing the subcategory/child, or a list of the available sub-categories of the three parent categories (with ids 27, 24 and 23):

    <?php if (is_category())
    {
    $category_id = get_query_var('cat');
    if ($category_id == '27' || $category_id == '24' || $category_id == '23') { ?>

      <?php wp_list_categories('child_of=$category_id'); ?>

    <? }
    else {
    /* USER IS ON A SUB-CATEGORY, SO SHOW POSTS */

    Thanks

  2. Pioneer
    Member
    Posted 1 year ago #

    Just use a theme that has a proper category page template.

  3. alchymyth
    Forum Moderator
    Posted 1 year ago #

    did you create a category.php for your theme?

    what is the full code of the template?

    what is the output if you echo the $category_id values?

    consider to post in your theme's forum at http://wordpress.org/support/theme/flato/

  4. ryanbuckley
    Member
    Posted 1 year ago #

    Thank you alchymyth. Yes, I did create a category.php theme, and the $category_id values are outputting as expected. I don't think it's a theme issue though, so not sure if it belongs in the flato forum.

    As per Pioneer's suggestion, I've been looking for themes that could do what I want, but I've found none.

    I'll explain in more detail.

    I want a main "Inventory" page, which will link to my two main catogories "Photographers" and "Categories". In each of these Parent pages, I would like to show a list of all the Sub-categories for only that parent category. Then, when the user clicks on a sub-category, all the posts for that sub-category are listed. The latter works, but the former parent-cateogry lists do not.

    I imagine this working like a folder system. Click on the parent folder, and you only see the contents of that 'folder'. Nothing I've seen in any other theme so far has been useful for me to appropriate.

    Here is my category.php code:
    http://codepad.org/xQE0tjfi

  5. ryanbuckley
    Member
    Posted 1 year ago #

    I've actually gotten it to work. I'll post my solution for others who may stumble upon this post in their own hunt.

    The code below will show all sub-categories to a parent category page, as long as you add those parent category IDs where they belong below:
    ` <h1><?php echo single_cat_title( '', false ); ?></h1>
    <?php if ( category_description() ) : // Show an optional category description ?>
    <div><?php echo category_description(); ?></div>
    <?php endif; ?>
    </header><!-- .archive-header -->
    </div>

    <div style="clear:both;"> </div>

    <?<!-- Start the loop -->
    if(have_posts()) : while(have_posts()) : the_post(); ?>

    <?php
    $this_category = get_category($cat);

    //if this is a parent category, only show sub-categories
    if (($this_category->cat_ID == 23) or ($this_category->cat_ID == 24) or ($this_category->cat_ID == 27)) { ?>

    <ul class="sub-categories">
    <?php wp_list_categories('sort_column=ID&sort_order=asc&list=1&optioncount=0&hide_empty=0&use_desc_for_title=1&children=0&child_of='.$this_cat.'&hierarchical=1&title_li='); ?>

    <?php /* end of Display sub-categories */ } ?>

  6. ryanbuckley
    Member
    Posted 1 year ago #

    My apologies. Here is the correct formatting:

    <h1><?php echo single_cat_title( '', false ); ?></h1>
    <?php if ( category_description() ) : // Show an optional category description ?>
    <div><?php echo category_description(); ?></div>
    <?php endif; ?>
    </header><!-- .archive-header -->
    </div>
    
    <div style="clear:both;"> </div>
    
    <? /* Start the loop */
    if(have_posts()) : while(have_posts()) : the_post(); ?>
    
    <?php
    $this_category = get_category($cat);
    
    //if this is a parent category, only show sub-categories
    if (($this_category->cat_ID == 23) or ($this_category->cat_ID == 24) or ($this_category->cat_ID == 27)) { ?>
    
    <ul class="sub-categories">
    <?php wp_list_categories('sort_column=ID&sort_order=asc&list=1&optioncount=0&hide_empty=0&use_desc_for_title=1&children=0&child_of='.$this_cat.'&hierarchical=1&title_li='); ?>
    
    <?php /* end of Display sub-categories */ } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic