Support » Themes and Templates » Template Tags for Subpages

  • I’ve got the following code that allows me to display all the subpages, regardless of what is the parent page. I was wondering if anyone can adapt this code to show the subpages that relate only to the parent page you are currently visiting. I want to keep the inline ‘link | link | link’ syntax.

    <?php
     		$querystr ="
    		SELECT $wpdb->posts.* FROM $wpdb->posts
    		WHERE $wpdb->posts.post_status = 'publish'
    		AND $wpdb->posts.post_type = 'page'
    		AND $wpdb->posts.post_parent > '0'
    		ORDER BY $wpdb->posts.menu_order ASC";
    		$pageposts = $wpdb->get_results($querystr, OBJECT);
    		?>
    		<?php if ($pageposts): ?>
            <?php foreach ($pageposts as $post): ?>
            <?php setup_postdata($post); ?>
            <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
            <?php the_title(); ?></a> |
            <?php endforeach; ?>
            <?php else : ?>
    		Not Found
    		<?php endif; ?>
    </div>
Viewing 1 replies (of 1 total)
  • Carl V

    (@carlos-amigos)

    If I understand your question right..then try this..

    change your where statement to say

    AND post_parent = “.$post->ID.”

Viewing 1 replies (of 1 total)
  • The topic ‘Template Tags for Subpages’ is closed to new replies.