WordPress.org

Ready to get started?Download WordPress

Forums

wp_list_pages() question (17 posts)

  1. adeking
    Member
    Posted 6 years ago #

    Hi,

    I am trying to hack at an existing theme and have become stuck.

    My blog has a horizontal top bar which is my main navigation. I have set the "depth" to 1 on this so that any sub-pages (or child pages as it were) do not display. In other words, only the parent pages of my blog appear in this top navigation.

    When a user clicks on a specific parent page. I want all the child pages for that parent to appear in a vertical sidebar.

    Can anyone let me know how I might do about doing this?

    Thanks - the site is http://www.macmillan-academy.org.uk/staff_blogs/mrking

  2. MichaelH
    Member
    Posted 6 years ago #

  3. adeking
    Member
    Posted 6 years ago #

    Hi,

    Sorry, but I am not looking for a collapsable menu. I need to display ONLY the second tier of pages for a specific parent.

    Thanks for your reply.

    Adrian

  4. Alex Cragg
    Member
    Posted 6 years ago #

    not entirely sure of the code, but look at conditional tags and querying the title.

    so you get the page title, and output wp_list_page but in the () put to only display child pages of the title you are on.

  5. Alex Cragg
    Member
    Posted 6 years ago #

    maybe something like...
    if(get_the_title($post->post_parent) != the_title(' ' , ' ',false)) { echo wp_list_pages('depth=-1'); }

    its a bit of a guess though, and probably wrong, but hopefully a pointer.

  6. adeking
    Member
    Posted 6 years ago #

    Hi,

    Yea, cheers this is what I am after. I too hada similar idea, but didnt know how to implement. I will see what I get with that.

    Any other suggestions most welcome....

  7. Alex Cragg
    Member
    Posted 6 years ago #

    maybe the child_of parameter might help...

  8. adeking
    Member
    Posted 6 years ago #

    Hi,

    Thanks for all your help epicalex but I am useless at PHP code - just a beginner really.

    I have been playing around with the code you sent, but I am not getting it to display the correct level of navigation.

    If annyone else would like to suggest a tutorial - or a piece of code that works then I will be over the moon!!!

    thanks

    Adrian

  9. sadish
    Member
    Posted 6 years ago #

    Most of my themes have this functionality built in.
    download for example my mistylook theme at http:://wpthemes.info/misty-look/version-3/ and take a look at the page.php file.

    Thats what you need.

    Sadish

  10. adeking
    Member
    Posted 6 years ago #

    Hi Sadish,

    Thanks very much for your reply. I have downloaded your excellent theme and am looking through it now.

    I cant find anything that looks like it could help on page.php, do I need to look through page-links.php? Or possibly sidebar.php?

    Is the functionality you are talking about on your theme options page? And if it is - does that mean it cannot be easily transfered to my theme?

    Thanks - and sorry for all the questions.

    Adrian

  11. sadish
    Member
    Posted 6 years ago #

    It must be in page.php and perhaps you missed it.

    lets do this.
    open up your theme's page.php and put this code http://pastebin.ca/491582 in it just below the call to the_content().

    See if it works.

    Sadish

  12. Karita
    Member
    Posted 6 years ago #

    I wanted to do almost the same thing with my website. I have only parent pages on the navigation tab, and also on the sidebar! Once you click on a page, it shows all the sub pages (offered by the mistylook theme, thanks Sadish!)
    What I used for my side bar was this:

      <?php
      wp_list_pages('exclude=1, 2, 3' ); ?>

    With 1, 2 and 3 being the Page_ID of the pages you don't want displayed on the sidebar.

  13. adeking
    Member
    Posted 6 years ago #

    Hi Sadish

    IT works!!!!!

    Love you!!!!!

  14. sadish
    Member
    Posted 6 years ago #

    Thanks Karita / adeking :)

    Its a pleasure !

    Sadish

  15. Alex Cragg
    Member
    Posted 6 years ago #

    sadish, i was wondering how this can work in a sidebar, im assuming it has to be called within the loop as it is? or am i just not getting it at all? ive got it working in index.php after have posts etc, but in the sidebar it produces nothing. thanks

  16. sadish
    Member
    Posted 6 years ago #

    epicalex,
    since this thread is marked as "resolved", you should post it in a new thread.

    but i have tested this code by putting it in the sidebar.php as well and is working in sidebar. paste it somewhere near the top of the sidebar.php before the call to the widgets.

    Sadish

  17. adeking
    Member
    Posted 6 years ago #

    Hi Sadish,

    I have taken this off as resolved just so I can ask another quick question. The sub-links for parent pages are working, however when you then click into a sub-page becasue the code is only looking to see if the "active" page has a parent - the navigation disappears. The best way to show this is for you to look at my blog.

    http://www.macmillan-academy.org.uk/staff_blogs/mrking/?page_id=13

    On this page I have created two sub-pages testing 123 and test. When the user clicks on testing123 I need the navigation for test to still be visible. The code I have used in my sidebar is below.

    <?php
    $sub_pages = wp_list_pages( 'sort_column=menu_order&depth=2&title_li=&echo=0&child_of=' . $id );
    if ($sub_pages <> "" ) {?>
     <div class="box-1">
                <div class="box-h">  
    
    	<h4><?php the_title(); ?></h4>
    
    <ul><?php echo $sub_pages; ?></ul>
    </div>
    	</div>
    	<?php }?>

    Hope you can continue to help....

Topic Closed

This topic has been closed to new replies.

About this Topic