有没有办法从wordpress中的分类学中获取所有帖子?
在taxonomy.PHP中,我有这个代码从与当前术语相关的术语中获取帖子.
- $current_query = $wp_query->query_vars;
- query_posts( array( $current_query['taxonomy'] => $current_query['term'],'showposts' => 10 ) );
- $myterms = get_terms('taxonomy-name','orderby=none&hide_empty');
- echo $myterms[0]->name;
有了你会发布第一个项目,然后可以创建一个foreach;循环:
这样你可以列出它们,如果你想发布所有这些,我的解决方案 – 在foreach中创建一个正常的wordpress循环,但它必须有一些类似的东西:
- foreach ($myterms as $term) :
- $args = array(
- 'tax_query' => array(
- array(
- $term->slug
- )
- )
- );
- // assigning variables to the loop
- global $wp_query;
- $wp_query = new WP_Query($args);
- // starting loop
- while ($wp_query->have_posts()) : $wp_query->the_post();
- the_title();
- blabla....
- endwhile;
- endforeach;
我贴了非常类似的here.