Home » Wordpress » Child page content

Child page content

Posted by: admin November 30, 2017 Leave a comment

Questions:

I have a parent page that acts as menu for my portfolio.

It pulls in thumbnail images from the child pages which i have been able to accomplish with magic fields and some code. It dumps the images into a grid layout. The thumbnails are pulled into one container div like so:

div id="folio-content">

<div class="thumb-container">
<div class="thumb"><img src="/images/pic.jpg"/>
</div>JCPenny</div>
... </div>`

when the div gets filled up with 2 thumbnails I want to create a new container div and fill it with 2 images again and so on after 2 images.

So, if you had 4 images it would look like this.

<div id="folio-content"><!--/Main Container/-->
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>JCPenny</div>
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>Champ Car</div></div>

<div id="folio-content"><!--/Main Container/-->
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>JCPenny</div>
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>Champ Car</div></div>



this is the code I am using in my page.php file.

    <?php get_header(); ?>

<div id="folio-content">

<?php
$projectpage = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');

$count = 0;
foreach($projectpage as $page)
{
$content = $page->post_content;
if(!$content)

continue;
if ($count == 10)  --- this is geting 10 images now,  but I want to get them all.

break;
$count++;

$content = apply_filters('the_content', $content);

?>
<div class="thumb-container">
<div class="thumb"><a href="<?php echo get_permalink($page->ID); ?>"<?php echo get_image ("thumbnail",1,1,1,$page->ID);?></a>
</div><?php echo $page->post_title ?>
</div>
<?php
}
?>
</div><!--/close set!-->
</div>

also, how can I get ALL child pages? I have it set to 10 now with this if ($count == 10)

any help? thanks a ton again!!!!

Answers:

I’m not familiar with “get_pages” but since WordPress treats posts and pages in an identical manner you could use this.

$projectpage = get_posts('numberposts=-1&post_type=page&child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');

The -1 removes the limit and gets ALL the specified pages.

Questions:
Answers:

I have cobbled together some code, that sort of sounds right but does not work at all! Which I am not surprised. But it is a starting point – please take a look at this code, maybe it is step in the right direction?

<?php
$projectpage = get_posts('numberposts=-1&post_type=page&child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
if (have_posts()) :
    $i=0; // counter
    while(get_posts()) : the_post();
        if($i%2==0) { // if counter is multiple of 3, put an opening div ?>
        <!-- <?php echo ($i+1).'-'; echo ($i+2); ?> -->
        <div>
        <?php } ?>
    <div class="single_item">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    </div>
        <?php $i++;
        if($i%2==0) { // if counter is multiple of 3, put an closing div ?>
        </div>
        <?php } ?>

    <?php endwhile; ?>
        <?php
        if($i%2!=0) { // put closing div here if loop is not exactly a multiple of 3 ?>
        </div>
        <?php } ?>

<?php endif; ?>