• I’ve got a sub navigation area on my site with code that uses conditional statements to display a section title for the level 1 category/page and follows it with a list of all the level 1’s subcategories/subpages.

    This title and list change when the section changes. So, if you’re in Book Reviews the subnav has a ‘Book Reviews’ title and subcategories list and if you’re in Rants the subnav has a ‘Rants’ title and subcategories list. It works the same on my Pages.

    HOWEVER, my big problem is that I can not get this to work on the singles/posts. I CAN get WordPress to list a single section’s subcategories on ALL the post ‘pages’. I just can’t get any conditional statements to work so that a book review shows JUST the Book Reviews subnav and a rant has just the Rants subnav.

    I’m frustrated as all-get-out.

    My site, for reference, is https://www.morevikings.com

    The code I can get to work is:

    echo "<ul>";
    wp_list_categories('orderby=name&hide_empty=0&child_of=1&title_li=<h2>Book Reviews</h2>');
    echo "</ul>";

    I have this difficulty whether I try conditional statements for this in sidebar.php or in single.php

    I’ve tried using is_single, in_category, is_category, etc.

    This is a theme I created and am developing.

    The following is the subnav code that is working on the Category and Page ‘pages’. It’s clunky but all I can get to work:

    <?php
    //
    if (is_home()) {
            // show a list of all top-level categories on home page
                 echo "<ul>";
                 wp_list_pages('orderby=name&child_of=111&title_li=<h2>More About moreVikings</h2>');
    			 echo "</ul>";
    // subnav for categories sections
    } elseif (is_category()) {
            // test if it's in the Book Review section and display a title and subcategories list
            if (is_category(array(1,17,18,19,20,21,22,23,24,25,30,31,32,33,34,35,36))) {
                 echo "<ul>";
                 wp_list_categories('orderby=name&hide_empty=0&child_of=1&title_li=<h2>Book Reviews</h2>');
                 echo "</ul>";
            // test if it's in the Rects and Rants section and display a title and subcategories list
             } elseif (is_category(array(41,42,43))) {
                  echo "<ul>";
                 wp_list_categories('orderby=name&hide_empty=0&child_of=41&title_li=<h2>Book Recs and Rants</h2>');
                 echo "</ul>";
            } else {
                  // catch-all for other categories
                  echo "&nbsp;";
            }
    // subnav for pages
    } elseif (is_page()) {
            // test if it's in the About section and display a title and subcategories list
            if (is_page(array(2,4,5,6,7,111))) {
                 echo "<ul>";
                 wp_list_pages('orderby=name&child_of=2&title_li=<h2>About moreVikings</h2>');
    			 echo "</ul>";
            } else {
                  // catch-all for other pages
                  echo "&nbsp;";
            }
    } else {
            // catch-all for everything else (archives, searches, 404s, etc)
            echo "&nbsp;";
    }
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Section Subnav on Single/Posts ‘Pages’’ is closed to new replies.