Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

ViscoDesign on "Page title and thumbnail outside loop"

$
0
0

I'm trying to get the featured image and page title, for a specific array of IDs, from outside the loop. After tinkering a bit I've got as far as displaying the thumbnail, but I can't figure out how to grab the title too. At the moment the <h2> is just empty.

Here's my code:

<?php
	$page_id = array('17', '15', '19', '13'); //stores multiple page ID in an array
	//render image for each page using foreach conditional loop
	foreach($page_id as $id){
		if (has_post_thumbnail($id) ):
		$image = wp_get_attachment_image_src( get_post_thumbnail_id($id, 'thumbnail') );
		endif; ?>
		<div class="teaser-box">
			<h2><a href="<?php echo the_title( $id ); ?>"></a></h2>
			<?php echo "<img src='".$image[0]."'>"; ?>
		</div>
<?php } ?>

I tried searching, but I'm not that great with PHP so not even sure of what I'm searching for. Any help much appreciated! Thanks.


Viewing all articles
Browse latest Browse all 8245

Trending Articles