I am trying to add thumbnails to a wordpress blog (that was created by someone else). As a newcomer to Wordpress I understand I need to add "the_post_thumbnail();" inside "the loop" but looking at the index.php file I dont see that there is a loop.
If you look at the code you can see i have tried to insert the the_post_thumbnail(); but looking at the front end http://www.chcdev.co.uk/blog/ there are still no thumbnails. (Yes I added a featured image to the posts aswell). Can any of you clever people shed any light on this?
<div id="main" class="grid_11">
<?php
// Settings
$blog_ids = array(5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,28);
$news_limit = 15;
$excerptsize = 250;
$pipes_url = 'http://pipes.yahoo.com/pipes/pipe.run? _id=ffc88cc14e18d87eb77c214c27f84e02&_render=json';
// Fetch recent posts for each blog and add them to an array indexed by date
foreach ($blog_ids as $b) {
switch_to_blog($b);
$posts = get_posts('&numberposts='.$news_limit.'&order=DESC&orderby=post_date');
foreach ($posts as $p) {
$news_tmp[strtotime($p->post_date_gmt)]['permalink'] = get_permalink($p->ID);
$news_tmp[strtotime($p->post_date_gmt)]['date'] = date("j", strtotime($p->post_date_gmt));
$news_tmp[strtotime($p->post_date_gmt)]['month'] = date("M", strtotime($p->post_date_gmt));
$author_arr = get_userdata($p->post_author);
$news_tmp[strtotime($p->post_date_gmt)]['author'] = $author_arr->display_name;
$news_tmp[strtotime($p->post_date_gmt)]['title'] = $p->post_title;
$news_tmp[strtotime($p->post_date_gmt)]['content'] = preg_replace('|\[(.+?)\](.+?\[/\\1\])?|s', '', strip_tags($p->post_content, '<p>'));
$news_tmp[strtotime($p->post_date_gmt)]['excerpt'] = '<p>' . substr( $news_tmp[strtotime($p->post_date_gmt)]['content'], 0, strrpos( substr( $news_tmp[strtotime($p->post_date_gmt)]['content'], 0, $excerptsize), ' ' ) ) . '...</p>';
}
}
// Fetch Yahoo pipes data and add them to an array indexed by date
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $pipes_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$pipes = json_decode($data, true);
$c=1;
foreach ($pipes['value']['items'] as $pipe) {
$d_parts = explode(' ', $pipe['pubDate']);
$t_parts = explode(':', $d_parts[4]);
$d = $d_parts[1]." ".$d_parts[2]." ".$d_parts[3]." ".$d_parts[4];
$news_tmp[strtotime($d)]['permalink'] = $pipe['link'];
$news_tmp[strtotime($d)]['date'] = ltrim($d_parts[1], '0');
$news_tmp[strtotime($d)]['month'] = $d_parts[2];
$news_tmp[strtotime($d)]['author'] = 'Yahoo!';
$news_tmp[strtotime($d)]['title'] = $pipe['title'];
$c++;
if ($c == $news_limit) {break;}
}
// Sort by the index (date)
ksort($news_tmp);
// Trim array to requested number of posts
$news = array_slice(array_reverse($news_tmp), 0, $news_limit);
// Display
foreach ($news as $n) {
echo " <div class=\"newspost\">\n";
echo " <h2><a href=\"".htmlentities($n['permalink'])."\" title=\"Permalink to ".$n['title']."\" target=\"_blank\">".$n['title']."</a></h2>\n";
echo "<div class=\"thumbnailmt\">\n";
the_post_thumbnail();
echo " </div>\n";
if( $n['author'] != 'Yahoo!') {
echo " <span class=\"author\">Written by: ".$n['author']." on " . $n['month'] . " " . $n['date'] . "</span>\n";
}
else{
echo " <span class=\"author\">Generated by Yahoo! Pipes. Written on " . $n['month'] . " " . $n['date'] . "</span>\n";
}
echo " <div class=\"main-divider\"></div>\n";
echo " " . $n['excerpt'] . "\n";
echo " </div>\n";
echo " <!-- END NEWS ITEM -->\n";
}
switch_to_blog(19);
?>
</div><!-- END MAIN -->