WordPress.org

Forums

category specific sidebar (4 posts)

  1. jdarby
    Member
    Posted 8 years ago #

    Hey everyone,
    I've read the articles regarding conditional tags and customizing the sidebar and ive started to implement some new code into WordPress. I'm trying to get certain information in my sidebar to display when specific categories are being displayed.

    My goal is to have parent/child nav links on the left sidebar for categories/sub categories that are within the CURRENT category that is being viewed. Here is a snippet of the code im currently working with:

    <?php
    if (is_home()) {
    echo "<ul>";
    wp_list_cats('optionall=0&sort_column=name&list=1&children=0');
    echo "<ul>";
    } elseif (is_category(35)) {
    echo "<ul>";
    wp_list_cats('categories=array(category35)');

    On the home page, it displays just the parent categories, which is good so far. But now on the specific category pages it is displaying parent/child links (good), but for ALL categories (bad). If someone can help me tweak the code so that i can get it to where when a user clicks the link that brings them to the "category35" page, only the category35 parent/child links display, thatd be great, thanks!

  2. jdarby
    Member
    Posted 8 years ago #

    tweaked the code a bit, still doesnt work, though. i figure ill post the most current stuff that im working with. thanks.

    <!-- begin sidebar -->
    <div id="sidebar">
    <?php
    // let's generate info appropriate to the page being displayed
    if (is_home()) {
    // we're on the home page, so let's show a list of all top-level categories
    echo "<ul>";
    wp_list_cats('optionall=0&sort_column=name&list=1&children=0');
    echo "</ul>";
    } elseif (is_category(32)) {
    // we're looking at a single category view, show relevant parent/child cats
    echo "<ul>";
    wp_list_cats('category=(category32)');
    echo "</ul>";
    } elseif (is_single()) {
    // displaying same as the home page, all cats, no children!
    echo "<ul>";
    wp_list_cats('optionall=0&sort_column=name&list=1&children=0');
    echo "</ul>";
    } elseif (is_page()) {
    // we're looking at a static page
    if (is_page('about')) {
    // our about page.
    echo "<p>This is my about page!</p>";
    } elseif (is_page('sample')) {
    echo "<p>this is the sample, running on WordPress " . bloginfo('version') . "</p>";
    } else {
    // catch-all for other pages
    echo "<p>should you be here?</p>";
    }
    } else {
    // catch-all for everything else (archives, searches, 404s, etc)
    echo "<p>nothing to see here!</p>";
    }
    ?>
    </div>
    <!-- end sidebar -->

  3. Zoutesnor
    Member
    Posted 8 years ago #

    You're using the code wp_list_cats('category=(category32)');, by my knowledge this isn't a valid WordPress syntax. I think you're looking for this: wp_list_cats('child_of=32');

  4. jdarby
    Member
    Posted 8 years ago #

    ok, with that change that you just suggested, i'm getting closer! with that code change it is not only displaying the child categories.

    } elseif (is_category(35)) {
    // we're looking at a single category view, show relevant parent/child cats
    echo "<ul>";
    wp_list_cats('child_of=35');
    echo "</ul>";

    My desired structure for the sidebar is:
    Parent
    Child
    Child
    and the current structure is
    Child
    Child
    any advice on how i could adjust this? thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic