WordPress Loop Through Particular Pages

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.

Read More

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.

Related posts

Leave a Reply

2 comments

  1. 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