WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] sidebar, conditional, category (2 posts)

  1. syncbox
    Member
    Posted 6 years ago #

    I have categories that do not have posts. They only have descriptions. However, I want them to still display when the list of cats are displayed and a cat link is clicked - even if that category has no posts.

    I can get this to happen, but the difference between clicking a cat link with posts versus no posts is what file is used to display content (category.php versus index.php)

    What I haven't figured out how to do is to get the same SIDEBAR content to display regardless of posts or no posts.

    Now, I understand that I can use the "else {}" at the end of all my conditions to force display of particular content... but that is already being used.

    any ideas?

  2. syncbox
    Member
    Posted 6 years ago #

    Solved. Maybe not elegant, but working...

    I changed the way my sidebar logic operates, using two levels of conditionals... so that I could say else {} twice, once only if_page() and at the end... without specifying whether page or category or single (basically, if using the index page, since the only time it is ever used is when clicking one of the categories AND no posts exist)

    <?php
    if (is_page()) {
    if($post->post_parent) { // page is a child
    wp_list_pages('depth=1&sort_column=menu_order&title_li=&child_of='.$post->post_parent);
    echo('');
    }
    elseif(wp_list_pages("child_of=".$post->ID."&echo=0")) { // page has children
    wp_list_pages('depth=1&sort_column=menu_order&title_li=&child_of='.$post->ID);
    echo('');
    }
    elseif (is_page(11)) {
    echo ('
    <p>stuff I want to show</p>
    ');
    }
    else { include (TEMPLATEPATH . '/file_i_want_to_show.php');
    }
    }
    elseif (is_category()) {
    echo '<h2>Text title here</h2>

      ';
      wp_list_categories('title_li=&orderby=name&hide_empty=0&child_of=54&use_desc_for_title=0');
      echo '
    ';
    }

    else {
    echo '<h2>Text title here</h2>

      ';
      wp_list_categories('title_li=&orderby=name&hide_empty=0&child_of=54&use_desc_for_title=0');
      echo '
    ';
    }
    ?>

    seems to work, though I am sure it is not elegant... so if there IS some way to test for using the index.php file (when clicking a cat list link where the cat has no posts) and then displaying specific sidebar content, I'm still all ears. meanwhile, I'll mark this resolved, since it seems to work.

Topic Closed

This topic has been closed to new replies.

About this Topic