【问题标题】:wordpress show all custom taxonomies and their associate postswordpress 显示所有自定义分类法及其相关帖子
【发布时间】:2011-10-04 12:38:33
【问题描述】:

他们在 wordpress 自定义分类中是否有任何方式来显示所有类别并关联他们的帖子意味着:

my category1
post 1
post 2
post 3
post 4


my category2
post 1
post 2
post 3
post 4

请注意,我必须在自定义帖子类型、分类中执行此操作。

【问题讨论】:

  • 在这种情况下有人可以帮助我吗?
  • 如果有人可以提供帮助,我会从我的声誉中提供 +100。谢谢
  • 你能再精确一点吗?你到底想完成什么?您想在下面列出一个分类的所有项目以及该分类中包含的所有帖子项目吗?为什么不使用标准的 wordpress 分类函数和嵌套的自定义查询?
  • “mycategory1”和“mycategory2”是分类法还是分类法术语? (例如,“华盛顿”可能是分类“城市”中的一个术语)......它们来自相同的帖子类型吗?您能否使用您想要使用的确切自定义帖子类型、分类法和一些示例帖子标题给出一个具体示例?这将帮助我形成一个更有帮助、更有意义的答案。

标签: wordpress


【解决方案1】:

这应该可以,我还没有彻底测试过

$args = array (
    'type' => 'post', //your custom post type
    'orderby' => 'name',
    'order' => 'ASC',
    'hide_empty' => 0 //shows empty categories
);
$categories = get_categories( $args );
foreach ($categories as $category) {    
    echo $category->name;
    $post_by_cat = get_posts(array('cat' => $category->term_id));

    echo '<ul>';
    foreach( $post_by_cat as $post ) {
        setup_postdata($post);
        echo '<li><a href="'.the_permalink().'">'.the_title().'</a></li>';
    }
    echo '</ul>';
}

来源:
http://codex.wordpress.org/Function_Reference/get_categories
http://codex.wordpress.org/Template_Tags/get_posts

问题只是问

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多