• Before I discovered this excellent piece of code from the Fauna template – I was creating a different template for each page so that I could display the links to the child pages as required.

    I have a question – the code will identify the parent page and output links to that parents’ child pages. How can I also print the parent page link just above the child links?

    Thanks

    <?php
    $currentpage = $post->ID;
    $parent = 1;

    while($parent) {
    $subpages = $wpdb->get_row("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = '$currentpage'");
    $parent = $currentpage = $subpages->post_parent;
    }
    $parent_id = $subpages->ID;
    $haschildren = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id'");
    $parent_title = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID = '$parent_id'");
    ?>

    <?php rewind_posts(); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php endwhile; endif; ?>
    <?php rewind_posts(); ?>

    <?php if($haschildren) { ?>
    <ul>
    <?php wp_list_pages('title_li=&child_of='. $parent_id); ?>
    </ul>
    <?php } ?>
    </div>

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘also print parent link along with child links’ is closed to new replies.