WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] calling featured images from child pages (2 posts)

  1. damian.smith
    Member
    Posted 1 year ago #

    Hey guys I have this function below, that calls the information of child pages into the parent page. All works perfectly except the featured images act strangely.

    The featured imahes should sit inside the featured-img div but for some reason they all sit outside of the ul completely, like so:

    <img...../>
    <ul class="childrens">
    <li>.... etc etc</li>
    </ul>

    Any ideas?? :/

    function get_children() {
    	global $post;
    
    	$args = array(
    		'post_parent' => $post->ID,
    		'post_type' => 'page'
    	);
    	$subpages = new WP_query($args);
    
    	// create output
    	if ($subpages->have_posts()) :
    		$output = '<ul class="childrens">';
    		while ($subpages->have_posts()) : $subpages->the_post();
    			$output .= '<li>
    						<div class="featured-img">'.the_post_thumbnail().'</div>
    						<div class="childrens-content">
    						<h3><a href="'.get_permalink().'">'.get_the_title().'</a></h3>
    						<p>'.get_the_excerpt().'<br />
    						</div>
    						<a class="read-more" href="'.get_permalink().'">Read More > ></a></p>
    						</li>';
    		endwhile;
    		$output .= '</ul>';
    	else :
    		$output = '<p>No subpages found.</p>';
    	endif;
    
    	// reset the query
    	wp_reset_postdata();
    
    	// return something
    	return $output;
    }
  2. damian.smith
    Member
    Posted 1 year ago #

    Sorted, I was being simple!

    just changed the_post_thumbnail to get_the_post_thumbnail

Topic Closed

This topic has been closed to new replies.

About this Topic