【发布时间】:2014-04-02 18:03:19
【问题描述】:
我正在尝试开发推荐插件。但它没有运行并给出以下错误消息..
插件无法激活,因为它触发了致命错误。
代码是:
add_filter('the_content','Recommender_function');
function Recommender_function(){
$id=get_the_id();
if(!is_singular('post')){
return $content;
}
$terms=get_the_terms($id,'category');
$categoriesarr=array();
foreach($terms as $term)
{
$categoriesarr[]=$term->cat_ID;
}
$loop=new WP_Query(
array('posts_per_page'=>4,'category__in'=>$categoriesarr));
if($loop->have_posts()){
$content.='<h2>I say, you should also try</h2>
<ul class ="Recommendation">';
while($loop-have_posts()){
$loop-the_post();
$content.='<li>
<a href="'.get_permalink().'">'.get_the_title().'</a></li>';
}
$content.='</ul>';
WP_reset_Query();
return $content;
}
}
知道我哪里出错了吗?
【问题讨论】:
-
正确的缩进和格式对故障排除有很大帮助。