Support » Fixing WordPress » Display Multiple Page Excerpts on Homepage

  • Resolved parrfolio

    (@parrfolio)



    I’m trying to display multiple page excerpts in buckets on the homepage. So far I have this code:

    <?php $page_query = new WP_Query('post_type=page&amp;post_parent=5&amp;order=ASC'); ?>
    <?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
      <div class="section">
      <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
     <?php the_excerpt(); ?>
    <p class="readmore"><a href="<?php the_permalink();?>">Read More</a>
    </div>
    <?php endwhile; ?>

    How can I add multiple ID’s of my choice? Something like this:

    <?php $page_query = new WP_Query('post_type=page&amp;post_parent=5,6,7,8,9,10&amp;order=ASC'); ?>

    I have been trying to figure this out for days! Any help would be greatly appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)
  • There’s isn’t a ‘multiple’ post_parent argument, but might look at:

    <?php
    $args=array(
      'post_type'=>'page',
      'post__in' => array(2,109,165)
       );
    $page_query = new WP_Query($args); ?>
    ?>

    Or use wpdb and build your own results.

    I think you want to do something like http://bloggercamp.com/blogging-tips/blogging-tips-wordpress-tips/remove-several-categories-from-the-loop-in-wordpress/ except you want to query for the specific categories, and display them. But that code snippet shows how to setup a query straight to the database.

    This works great. Thank you. On last question: Is it possible to list the pages in order of the array?

    ‘post__in’ => array(5,18,85,268,120,49), = bucket 5, bucket 18, bucket 85…

    Look at the orderby choices.

    Great! Thanks for all the help.

    final code:

    <?php
      $args=array(
      'orderby' =>'parent',
      'order' =>'asc',
      'post_type' =>'page',
      'post__in' => array(85,18,5,118,120,268),
       );
       $page_query = new WP_Query($args); ?>
    
    <?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
       <div class="section">
    	<h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
    	<?php the_excerpt(); ?>
            <p class="readmore"><a href="<?php the_permalink();?>">Read More</a></p>
    	<span class="perm"><a href="<?php the_permalink();?>">Permalink</a></span>
        </div>
    <?php endwhile; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display Multiple Page Excerpts on Homepage’ is closed to new replies.