限制子页的数量

时间:2013-01-28 作者:rob.m

我有以下html结构:

<home>
<Web>
   <web 1>
   <web 2>
   <web 3>
   <web 4>
   <web 5>
   <web 6>
   <web 7>
 </web>
<Print>
   <Print 1>
   <Print 2>
   <Print 3>
   <Print 4>
   <Print 5>
</print>
<Art>
   <Art 1>
   <Art 2>
   <Art 3>
   <Art 4>
   <Art 5>
   <Art 6>
</art>
</home>
我使用它来显示孙子的内容,同时隐藏其父内容

<?php $counter = 1 ?>
<div class="row-fluid">

<?php 
if ( have_posts() ) {
while ( have_posts() ) {
    the_post();

    $args=array(
            \'orderby\' => \'menu_order\',
            \'order\' => \'ASC\',
            \'posts_per_page\' => -1,
    \'post__not_in\' => array(4,368,358,354),
            \'post_type\' => \'page\',
            \'post__in\' => $pageIDs
    );

    $childpages = new WP_Query($args);

    if($childpages->post_count > 0) { /* display the children content  */
        while ($childpages->have_posts()) {
             $childpages->the_post(); ?>
    <div class="span4">
                <?php 
            echo "<h2>".get_the_title()."</h2>";
                    echo the_content(); 
        ?>
    </div>
    <? if ($counter % 3 == 0): ?>
    </div>
    <div class="row-fluid">
        <?php endif; ?>
    <?php $counter++; ?>

       <?php }
    }
    wp_reset_query();
}
}

?>
</div>
在显示所有孙子的时候,我如何将孙子的数量限制为每种类型3个(打印3个,网络3个,艺术3个)?

1 个回复
SO网友:rob.m

我就是这样解决的:

<?php
 /*
  Template Name: home
  */
  get_header(); ?>

 <?php $counter = 1 ?>
 <div class="row-fluid"> 
 <?php
$args = array(
 \'child_of\' => 4,
 \'parent\' => 0,
 \'post_type\' => \'page\',
 \'post_status\' => \'publish\'
); 
 $childrens =   query_posts(\'showposts=3&post_parent=4&post_type=page&orderby=menu_order&order=DESC\');

  foreach ( $childrens as $children ) :
 query_posts(\'showposts=3&post_parent=\'.$children->ID.\'&post_type=page&orderby=menu_order&order=DESC\');
if ( have_posts ) :
while ( have_posts() ) : the_post();
 ?>
    <div class="span4">
        <h2>
            <?php the_title(); ?>
        </h2>
        <?php the_content(); ?>
    </div>
  <? if ($counter % 3 == 0): ?>
 <div id="content" class="row-fluid"></div>
</div>
<div class="row-fluid">
   <?php endif; ?>
    <?php $counter++; ?>
<?php
endwhile;
 endif;
endforeach;
?>
 </div>

<?php get_footer(); ?>

结束