0

I have the following code setup as a page template and assigned to a page:

        <?php if ( have_posts() ) : 
        while ( have_posts() ) : the_post(); ?>
            <?php
            echo $post->ID;
            $thumb = get_post_meta($post->ID, 'Thumbnail', true);
            ?>
            <p><img src="<?php echo $thumb; ?>"</p>         

            <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

                <h1><?php the_title(); ?></h1>

                <?php the_excerpt();  ?>

                <?php the_content(); ?>
            </div><!-- #post-## -->

        <?php endwhile; ?>
    <?php endif; ?>

I curently have this page template on post=21. Now this all work fine but it only works for the page this template is assigned to.

I actually don't want this to be part of a template but I just want to use the code within my index.php file but I actually would like it to loop through these pages, i.e. 21,22,23 only, inorder to retrieve the info I have requested here.

Can someone please assist on how to pass the page id into this loop or how to make it loop just through pages 21,22 and 23.

This has got me stuck.

Thanks.

  • Please work on your questions. You got dozens of answers. If one fits: Mark it as solution. If not: comment. Thanks. – kaiser Sep 21 '12 at 12:14
1

before your code, add:

<?php query_posts( array( 'post_type' => 'page, 'post__in' => array(21,22,23), 'orderby' => 'ID', 'order' => 'ASC') ); ?>

http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

0

Perhaps something like this

$thepages = array (21,22,23);
foreach ($thepages as $thepage) {
  $page_data = get_page( $thepage );
  echo "<h3>$page_date->post_title</h3>";
  echo apply_filters('the_content', $page_data->post_content);
  // spray out other page content
 }

See more here

  • thanks for that but just wondering, how can I access a post thumbnail that I have setup as a custom field of 'thumbnail' using your approach. Thanks. – softprinciples Mar 23 '12 at 14:33
  • should use get_pages and do it one query rather than 3 queries in a loop, more efficient. – Milo Mar 23 '12 at 15:29
  • I tried the get_pages approach and couldn't get it going - is there anything different I need to do apart from the function call? – softprinciples Mar 23 '12 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.