WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Show children pages only when parent is 'current' page (wp_list_pages) (11 posts)

  1. sincewelastspoke
    Member
    Posted 4 years ago #

    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.

  2. chinmoy
    Member
    Posted 4 years ago #

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

    try this code.

  3. sincewelastspoke
    Member
    Posted 4 years ago #

    Hi chinmoy. Thanks for the quick reply.

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

    Any ideas?

  4. sincewelastspoke
    Member
    Posted 4 years ago #

    Any ideas?

  5. chinmoy
    Member
    Posted 4 years ago #

    sorry!! it would be $post->post_parent

  6. sincewelastspoke
    Member
    Posted 4 years ago #

    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

  7. chinmoy
    Member
    Posted 4 years ago #

  8. sincewelastspoke
    Member
    Posted 4 years ago #

    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.

  9. Mark / t31os
    Moderator
    Posted 4 years ago #

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

  10. sincewelastspoke
    Member
    Posted 4 years ago #

    'Flexi Pages' worked a treat. Many thanks Mark.

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

  11. Khaled Hakim
    Member
    Posted 3 years ago #

    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; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.