我正在尝试向wordpress博客(由其他人创建)添加缩略图。作为Wordpress的新手,我知道我需要添加“the\\u post\\u thumbnail();”在“循环”内部,但查看索引。php文件我没有看到有循环。
如果您查看代码,可以看到我尝试插入了the\\u post\\u缩略图();但看看前端http://www.chcdev.co.uk/blog/ 仍然没有缩略图。(是的,我也在帖子中添加了一幅特色图片)。你们这些聪明的人能解释一下吗?
<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 -->