I am trying to create a landing page for a section of a clients site. I have created a custom page that the content will be out on and what I want to do is to pull out the title and featured image for each page onto this landing page in a thumbnail gallery format.
I also want to have the landing pages own title and content area so the admin has control of the page summary. I'm not too hot on custom queries so got a bit stuck at this point.
I have put my code so far below. I know how to get the title and post thumbnail out is just just the code to select children of the parent page I am struggling with.
<?php
/*
Template Name: Label Homepage*/
?>
<?php get_header(); ?>
<div id="full-width">
<h1 id="music"><span>Moda Music Label</span></h1>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
<h2>Releases</h2>
<?php
$args=array(
'post_type'=>'page',
'child_of' => $post->ID
);
$the_query = new WP_Query($args);
?>
<?php while (have_posts()) : the_post(); ?>
<?php the_title(); ?>
<?php endwhile;?>
</div>
<?php get_footer(); ?>
Michael Fields answers:
$children = get_children( array(
'post_parent' => $post->ID,
'post_type' => 'page',
'numberposts' => -1,
'post_status' => 'publish'
) );
$post_backup = $post;
foreach( (array) $children as $post ) {
setup_postdata( $post );
the_title();
the_content();
}
$post = $post_backup;
Juanfra Aldasoro answers:
Hi mate,
Utkarsh Kukreti is right.
Then:
You should load the query values for that specific query and then display the loop with the title and if there's an image, the image. Something like this:
$the_query = new WP_Query($args);
while ( $the_query->have_posts() ) : $the_query->the_post();
//....
//whatever you need to do
//....
the_title();
if ( has_post_thumbnail() ) :
// the current post has a thumbnail
the_post_thumbnail('thumb-size');
endif;
endwhile;
I hope this helps :)
Cheers,
Juan
Andrew Cetnarskyj answers:
Hi guys thanks for your replies.
Juanfra and Utkarsh your answers only returned one result but michaels returned what I needed :)