我试图在我的主页上显示一些Wordpress类别缩略图,但我的代码似乎破坏了我网站的其余部分。它会杀死页面,我的代码下的任何内容都不会加载。
如果您能提供帮助,我们将不胜感激。
谢谢
<?php
global $post;
$temp_post = $post;
$args = array(\'numberposts\' => 1, \'category\' => 40, \'orderby\' => \'date\', \'order\' => \'DESC\');
$posts = get_posts($args);
foreach ($posts as $post) : setup_postdata($post);
if (has_post_thumbnail()) {
$thumbnail = get_post_thumbnail($post->ID, \'thumbnail\');
$title = get_the_title();
$output = $title . "<br />" . $thumbnail;
}
endforeach;
$post = $temp_post;
wp_reset_postdata();
return($output);
?>
EDIT
<?php
global $post;
$temp_post = $post;
$args = array(\'numberposts\' => 6, \'category\' => 227, \'orderby\' => \'date\', \'order\' => \'DESC\');
echo \'<div class="categoryThumbnailList">\';
$posts = get_posts($args);
foreach ($posts as $post) : setup_postdata($post);
if (has_post_thumbnail()) {
$thumbnail = get_the_post_thumbnail($post->ID, \'thumbnail\');
$link = get_permalink($post->ID);
$title = get_the_title();
echo \'<div class="categoryThumbnailList_item">\';
echo \'<a href="\' .$link . \'" title="\' .$title . \'">\' .$thumbnail . \'</a><br/>\';
echo \'<a href="\' .$link . \'" title="\' .$title . \'">\' .$title . \'</a>\';
echo \'</div>\';
}
endforeach;
echo \'</div>\';
echo \'<div class="categoryThumbnailList_clearer"></div>\';
$post = $temp_post;
wp_reset_postdata();
?>