I have this html structure:
<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>
I use this to display the grandchildren content while hiding its parent
<?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>
At the moment all grandchildren are displayed, how do I limit the number of grandchildren to be 3 per type (3 for the print, 3 for the web and 3 for the art)?
First I would try to not use more queries then required. Assuming you know (or know how to get) the
$id
(as an integer) of the parent post, use the post_parent parameter:Try #2:
Let me know please what you got with this code examples.