WordPress.org

Ready to get started?Download WordPress

Forums

wp_list_cats exclude categories in sidebar (5 posts)

  1. clarissa
    Member
    Posted 7 years ago #

    I have tried the following code:

      <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0&exclude=1, 6'); ?>

    but my category list resulted in "None". Can someone help? Much appreciation! :)

  2. ladydelaluna
    Member
    Posted 7 years ago #

    well a link to your site might be helpful...

    <ul>
    <?php wp_list_cats('sort_column=name&optioncount=1&exclude=10, 15'); ?>
    </ul>

    That's the example given in the codex: http://codex.wordpress.org/Template_Tags/wp_list_cats

    Try copying it exactly, and replace your category numbers, and see what happens...

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Do you have categories other than 1 and 6, which are also not children of category 1 or 6?

    I think (but am not 100% sure) that if you disable hierarchical, the children categories will not show at all, it'll only display the top level categories.

    So if 1 and 6 are the only two top level cats, you'll get nothing back from that request. If you want to display *just* the children of a cat, you need to use the child_of parameter.

    See here for more info: http://codex.wordpress.org/Template_Tags/wp_list_cats

  4. clarissa
    Member
    Posted 7 years ago #

    Thank you for the fast replies!

    ladydelaluna - I've copied the code exactly but it still showed as "No categories".

    Otto42 - I do have categories other than 1 and 6. Currently, I have eight total.

    Here is the complete code of my sidebar.php (from Blix)

    <hr class="low" />

    <!-- subcontent ................................. -->
    <div id="subcontent">

    <?php /**
    * Pages navigation. Disabled by default because all new pages are added
    * to the main navigation.
    * If enabled: Blix default pages are excluded by default.
    */
    ?>
    <h2>Pages</h2>
    <ul class="pages">
    <?php
    $excluded = BX_excluded_pages();
    wp_list_pages('title_li=&sort_column=menu_order&exclude='.$excluded);
    ?>

    <?php if (is_home() || is_page()) { ?>

    <?php
    /**
    * If a page called "about_short" has been set up its content will be put here.
    * In case that a page called "about" has been set up, too, it'll be linked to via 'More'.
    */
    $pages = BX_get_pages('with_content');
    if ($pages) {
    foreach ($pages as $page) {
    $page_id = $page->ID;
    $page_title = $page->post_title;
    $page_name = $page->post_name;
    $page_content = $page->post_content;

    if ($page_name == "about") $more_url = 'More';
    if ($page_name == "about_short") {
    $about_title = $page_title;
    $about_text = BX_remove_p($page_content);
    }
    }
    if ($about_text != "") {
    echo "<h2>".$about_title."</h2>\n";
    echo "".$about_text;
    if ($more_url != "") echo " ".$more_url;
    echo "\n";
    }
    }
    ?>

    <h2>Categories</h2>

    <ul class="categories">
    <?php wp_list_cats('sort_column=name&optioncount=1&exclude=1, 2'); ?>

    <h2>Authors:</h2> <ul class="categories">
    <?php wp_list_authors('exclude_admin=0&hide_empty=0'); ?>

    <?php } ?>

    <?php if (is_single()) { ?>

    <h2>Calendar</h2>

    <?php get_calendar() ?>

    <h2>Most Recent Posts</h2>

    <ul class="posts">
    <?php BX_get_recent_posts($p,10); ?>

    <?php } ?>

    <?php if (is_page("archives") || is_archive() || is_search()) { ?>

    <h2>Calendar</h2>

    <?php get_calendar() ?>

    <?php if (!is_page("archives")) { ?>

    <h2>Posts by Month</h2>

    <ul class="months">
    <?php get_archives('monthly','','','

  5. ','
  6. ',''); ?>

    <?php } ?>

    <h2>Posts by Category</h2>

    <ul class="categories">
    <?php wp_list_cats('sort_column=name&hide_empty=0'); ?>

    <?php } ?>

    </div> <!-- /subcontent -->

  • orantesgallery
    Member
    Posted 7 years ago #

    ladydelaluna - This is exactly what I needed. Thanks for posting

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags