Forums

wp_list_categories() returns "No categories" (8 posts)

  1. StephanHeijl
    Member
    Posted 1 year ago #

    While using Wordpress 2.6.3 to build a news site, I tried to use wp_list_categories() to make a lost of my categories in my sidebar. However, while I certainly have 5 of them, this command returns "No categories."
    I originally used the 2.7 beta, and thought it was a bug, however the change of version did not affect the problem.
    Here's the exact code I used:

    <div id="menu">
    <div class="menutop"><span class="header">Menu</span></div>
    <span class="header">Posts uit:</span>
    
    <ol>
    <li><?php wp_list_categories(); ?></li>
    </ol>
    <div id="menufoot"></div>
    </div>

    It was used on this page:

    http://86.91.64.66/Subs/Kandinsky_WP/index.php

    I already searched Google and this site for answers, but the topics regarding this question were 4 months old, and unanswered.

  2. mercime
    Member
    Posted 1 year ago #

    a category appears in list when there is at least one post associated with that category.

  3. StephanHeijl
    Member
    Posted 1 year ago #

    As you could see on the page, I already had a post on there with 2 categories. I added a second one, and yet to no avail. I don't think that this is the cause of the problem.

  4. StephanHeijl
    Member
    Posted 1 year ago #

    I set the second one to have 2 other categories. When I add the_category() in the menu it displays the categories of the first post, just to prove the categories are still there.

    <div id="menu">
    <div class="menutop"><span class="header">Menu</span></div>
    <span class="header">Posts uit:</span>
    
    <ol>
    <li><?php wp_list_categories(); ?></li>
    </ol>
    
    <ol>
    <li><?php the_category(); ?></li>
    </ol>
    
    <div id="menufoot"></div>
    </div>

    Once again the code I used, and here's the URl:

    http://86.91.64.66/Subs/Kandinsky_WP/index.php

  5. mercime
    Member
    Posted 1 year ago #

    Based on the source of your customized theme, the sidebar is set up before the main content, also
    - the_category is used within THE LOOP, so if it is showing up in your sidebar, then you started THE LOOP before your sidebar.
    - wp_list_categories is used outside THE LOOP, in other words, start THE LOOP after the sidebar tags
    - You also have validation errors . Most of errors caused by wrong codes such as:

    <ol>
    <li><?php wp_list_categories(); ?></li>
    </ol>

    should be

    <ol>
    <?php wp_list_categories(); ?>
    </ol>

    WP Theme Template Reference

  6. StephanHeijl
    Member
    Posted 12 months ago #

    Thanks! Putting the menu after the posts worked like a charm :D

  7. tprod
    Member
    Posted 12 months ago #

    Are you sure that wp_list_categories(); must be after the loop here is my code :

    <div id="content">
        <div class="left">
           <?php if(strlen(category_description($category))> 7){ ?>
            <div class="category-presentation"><?php echo category_description($category); ?></div>
            <?php } ?>
            <h2><?php echo(get_category_parents($cat, TRUE, ' &raquo; ')); ?></h2>
           <?php //if(!empty($category)){ ?><ul id="category"><?php wp_list_categories('orderby=name&show_count=0&title_li=&child_of='.$cat); ?></ul><?php //} ?>
        </div>
    
        <div class="right">
    		<?php query_posts('cat='.$cat); ?>
            <?php while (have_posts()) : the_post(); ?>
            <div class="post">
                <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                <p><?php echo the_content(); ?></p>
            </div>
            <?php endwhile; ?>
        </div>
        <div class="clr"></div>
    </div>

    The result when I navigate through categories is "No categories" ? Do you have a solution ?

  8. mercime
    Member
    Posted 12 months ago #

    tprod: the solution I gave above was specifically for StephanHeijl's specific set up based on the theme where the sidebar was placed before the content. Just remember to keep wp_list_categories OUTSIDE of the loop. If you want to list the categories you checked for the post, use the_category

Topic Closed

This topic has been closed to new replies.

About this Topic