Show a certain number of child pages for a parent on the homepage
-
Hi all,
I’m about a 1 out of 100 for my WordPress skill level but I’m giving it a go and doing well so far.
Here’s my dilemma.
I’ve got the current page structure
Home
– Portfolio
—– Portfolio item 1
—– Portfolio item 2
—– Portfolio item 3
—– Portfolio item 4
—– Portfolio item 5
—– Portfolio item 6
—– etcI can get the portfolio page to show each of the portfolio item pages feature image and title fine.
My next step it so the latest 4 portfolio items feature image and title on the homepage.
Currently the code I’m using on the portfolio page to show the child pages is:
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php
$children = get_pages(‘child_of=’.$post->ID);
if( count( $children ) != 0 ) { }
else { echo “There are currently no portfolio items to show”; }?>
<?php
$child_pages = $wpdb->get_results(“SELECT * FROM $wpdb->posts WHERE post_parent = “.$post->ID.” AND post_type = ‘page’ ORDER BY menu_order”, ‘OBJECT’); ?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?><li class=”col2″>
ID); ?>” rel=”bookmark” title=”<?php echo $pageChild->post_title; ?>”><?php echo get_the_post_thumbnail($pageChild->ID, ‘medium’); ?>
<div class=”portfolio-thumbnail-info”>
<h3 class=”title”>ID); ?>” rel=”bookmark” title=”<?php echo $pageChild->post_title; ?>”><?php echo $pageChild->post_title; ?></h3>
</div><?php endforeach; endif;
?><?php endwhile; // end of the loop. ?>
All I need now is the code to include on the homepage template to show the latest 4 portfolio item pages.
I must stress, I’m a complete beginner with WordPress and PHP. The code I used above was found on a forum which I tweaed to include the title and feature image.
Currently using WordPress 3.3
Cheers,
James
- The topic ‘Show a certain number of child pages for a parent on the homepage’ is closed to new replies.