有关使用分类法为自定义帖子创建过滤器的问题

时间:2011-07-12 作者:user6979

这是我第一次尝试自定义帖子类型和分类法。我创建了一个分类服务。php页面显示与“网站”slug关联的帖子。这似乎很有效。

但是,我希望能够显示其他有关服务的帖子。与另一个slug关联的php,如“video”。

这两者都属于服务分类。我只是不知道如何在服务中过滤它们。php页面。

有人能帮我完成这个挑战吗。我是PHP和WordPress的noob,需要在这一点上快速获胜。

1 个回复
SO网友:Bainternet

您可以检查分类服务。php当前查询的术语过滤器基于什么,如下所示:

//get the current term
$term_slug = get_query_var( \'term\' );
//get the current taxonomy
$taxonomyName = get_query_var( \'taxonomy\' );
//get the term object if you want
$current_term = get_term_by( \'slug\', $term_slug, $taxonomyName );

//then you can query your posts/custom based on that term
$s_query = NEW WP_Query(array(\'services\' => $term_slug, \'post_type\' => \'post\'));

//then you can simply filter the posts
if ($current_term->term_slug == "websites"){
   while($s_query->have_posts){
      $s_query->the_post();
      //do websites loop
   }
}elseif ($current_term->term_slug == "video"){
   while($s_query->have_posts){
      $s_query->the_post();
      //do videos loop
   }
}else{
   while($s_query->have_posts){
      $s_query->the_post();
      //do any other loop of that taxonomy
   }
}

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register