WordPress.org

Ready to get started?Download WordPress

Forums

Child pages post_thumbnail (2 posts)

  1. richgcook
    Member
    Posted 1 year ago #

    I have the following code, which is meant to pull in the child page's of the page ID 14 featured image, and I can't work out why it's not working. It's doing nothing at all...

    <?php $ID = get_the_ID();
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		query_posts("post_type=page&post_parent=$ID&order=ASC&orderby=menu_order&child_of=14&posts_per_page=1&paged=$paged"); while ( have_posts() ) : the_post(); ?>
    				<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
    				<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
    				</a>
    		<?php endwhile; ?>
    		<?php wp_reset_query();?>

    I also changed this code around to display

    <?php query_posts("post_type=page&order=ASC&orderby=menu_order&child_of=14&posts_per_page=2"); while ( have_posts() ) : the_post(); ?>
    				<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
    				<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
    				</a>
    		<?php endwhile; ?>
    		<?php wp_reset_query();?>

    Which outputs the anchor tags but not the child pages of 14 - it just outputs all the pages.

    Any help would be really appreciated.

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    possibly try to work with get_pages() http://codex.wordpress.org/Function_Reference/get_pages

    child_of does not seem to be a query parameter, therefore try to remove it:

    query_posts("post_type=page&post_parent=$ID&order=ASC&orderby=menu_order&posts_per_page=1&paged=$paged"); while ( have_posts() ) : the_post(); ?>

    and check that:
    $ID = get_the_ID();
    grabs the right ID;
    otherwise try to use:
    $ID = $post->ID;

Topic Closed

This topic has been closed to new replies.

About this Topic