• Resolved kjeft

    (@kjeft)


    Hello all,

    I have a bit of a problem displaying my navigation properly. I have divided my site into three sections, all operating as different sites, just connected with a static main navigation (Main 1, Main 2 and Main 3) so that users can easily flick between the different ‘sites’. (Like this! Beware the page is a mess)

    Then below the static main navigation I list the sub pages using this piece of code:

    <?php
          if($post->post_parent)
          $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
          else
          $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
          if ($children) { ?>
          <ul>
    	  	<?php echo $children; ?>
          </ul>
    <?php } ?>

    It works great but I would like to add a ‘Home’ button (displayed in the same fashion as the sub page links) that will take you to the parent page for each section.

    I know I already have my static main buttons displayed but I want to include a ‘Home’ as well, but just can’t figure it out. My php skills aren’t excellent but I have still tried so many versions using the wp_page_menu template but never got it working. Perhaps wp_page_menu isn’t the way to do this?

    If anyone have any ideas please let me know!

    Oh and I also want it to work with the li.current_page_item a CSS class.

    Hope this makes sense and isn’t too complicated… Thanks in advance!

    em

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi

    In the old days (as in, last year) there was not a wp_page_menu function. wp_list_pages was used (same options as wp_page_menu) and the Home option was entered manually by adding an <li> ahead of the call to wp_list_pages in header.php. In some uses this method works better and it sounds like that’s true for you.

    In terms of the active class, I do it like this
    <li<?php if(is_page('whatever') echo ' "class="current_page_item" '; ?>><a href="/whatever/">Home</a></li>

    If it is the site’s home page you have to use is_front_page() instead of is_page(‘whatever’). Instead of ‘whatever’ on is_page, use either the page slug or the page ID.

    Thread Starter kjeft

    (@kjeft)

    Perfect. With a bit of tweaking I even managed to get it working in the header.php all nice and dynamic ?? Smoother than ever,
    Thanks Steve!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List ‘Home’ and children only’ is closed to new replies.