WordPress.org

Ready to get started?Download WordPress

Forums

also print parent link along with child links (2 posts)

  1. checksum
    Member
    Posted 8 years ago #

    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>

  2. Bedient
    Member
    Posted 7 years ago #

    Did you ever get this working? I think this is what I want to do.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic