• Hi all!

    I have this code that returns the thumbnail of this post.

    <?php
        if (have_posts()) : while (have_posts()) : the_post();
            if (has_post_thumbnail()) :
                	the_post_thumbnail('no-scale-thumb');
            endif;
        endwhile; endif; 
    ?>

    Now I am trying to wrap this thumbnail image with a link to the last-published page that is a child of another page (id=13). So when a user clicks on the image he’s taken to the latest recipe (recipes are published as children of Recipes page).

    Your help is appreciated. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Maybe try something like this:

    // WP_Query arguments
    $args = array(
    	'post_parent'            => '13',
    	'nopaging'               => true,
    	'posts_per_page'         => '1',
    	'order'                  => 'DESC',
    	'orderby'                => 'date',
    );
    
    // The Query
    $query = new WP_Query( $args );
    
    // The Loop
    if ( $query->have_posts() ) {
    	while ( $query->have_posts() ) {
    		$query->the_post();
    		if (has_post_thumbnail()) :
                	?>
                	<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                		<?php the_post_thumbnail('no-scale-thumb'); ?>
                	</a>
            <?php
            endif;
    	}
    } else {
    	// no posts found
    }
    
    // Restore original Post Data
    wp_reset_postdata();
    • This reply was modified 7 years, 5 months ago by John Regalado.
    Thread Starter Bittabola

    (@bittabola)

    Thank you! Will try out.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Linking to the latest page which is a child of a specific page’ is closed to new replies.