Support » Fixing WordPress » Show children pages only when parent is 'current' page (wp_list_pages)

  • Resolved sincewelastspoke

    (@sincewelastspoke)


    Hi,

    I’m using this:
    <?php wp_list_pages('exclude=31,36,39&sort_column=menu_order&title_li='); ?>
    to display a list of all my ‘parent’ pages.

    I’d like it so if the user is on one of these pages (and it has children) that these children are then displayed underneath it in the HTML output.

    Does anyone have experience of doing something similar to this?

    Many thanks for any help.

Viewing 10 replies - 1 through 10 (of 10 total)
  • chinmoy29

    (@chinmoy)

    <?php
    if($post->parent){
    wp_list_pages(‘child_of=$post->ID&sort_column=menu_order&title_li=’);
    }
    ?>

    try this code.

    sincewelastspoke

    (@sincewelastspoke)

    Hi chinmoy. Thanks for the quick reply.

    Unfortunately, it doesn’t seem to display anything when I use this.

    Any ideas?

    sincewelastspoke

    (@sincewelastspoke)

    Any ideas?

    chinmoy29

    (@chinmoy)

    sorry!! it would be $post->post_parent

    sincewelastspoke

    (@sincewelastspoke)

    It still doesn’t seem to like it:

    <?php
        if($post->post_parent){
          wp_list_pages('child_of=$post->ID&sort_column=menu_order&title_li=');
          }
        ?>

    I’m using it in footer.php

    Is this OK to do it like this?

    Thank you

    chinmoy29

    (@chinmoy)

    sincewelastspoke

    (@sincewelastspoke)

    Thanks chinmoy.

    I’ve been using that as a reference, but still no further :'(

    I’ve googled about and found a few people with similar issues get results, but when I use their code, it just doesn’t work.

    Have a look at the following plugin, and see if that helps..
    http://wordpress.org/extend/plugins/flexi-pages-widget/

    sincewelastspoke

    (@sincewelastspoke)

    ‘Flexi Pages’ worked a treat. Many thanks Mark.

    And thanks to chinmoy29 for your efforts too, much appreciated.

    Khaled Hakim

    (@khaledhakimgmailcom)

    This lists 10 pages of the “current” post type on a particular page.
    You can modify variables as you like.

    <?php $typeofpost = get_post_type( $post ); ?>			
    
    <?php
    $args = array( 'post_type' => $typeofpost, 'posts_per_page' => 10,  'order'=>'ASC' );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();?>
    <li><a href="<?php the_permalink();?>" title="<?php the_title();?>"><?php the_title();?></a></li>
    <?php endwhile; ?>
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Show children pages only when parent is 'current' page (wp_list_pages)’ is closed to new replies.