2

是否有任何简单的方法可以使用永久链接列出自定义帖子类型的所有分类法?

taxonomy=title&post_type=company

以下内容不起作用,它仅列出帖子的类别:

$args = array (
    'type' => 'company', //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>';
}
4

3 回答 3

6

尝试改变

'type' => 'company', //your custom post type

'post_type' => 'company', //your custom post type
于 2012-10-12T21:16:06.193 回答
2

改变

'type' => 'company', // your custom post type

'taxonomy' => 'yourtaxonomyname', // your custom taxonomy

另见http://codex.wordpress.org/Function_Reference/get_categories

于 2015-03-10T22:18:15.200 回答
-2

这应该有效:

$index_query = new WP_Query(array('post_type' => 'company', 'posts_per_page' => '-1', 'order' => 'DESC'));

while ($index_query->have_posts()) : $index_query->the_post();

    $taxonomy_ar = get_the_terms($post->ID, 'tax-name');

    $output = '<span class="btn">';
    foreach($taxonomy_ar as $taxonomy_term) {
        $output .= '<a href="'.get_term_link($taxonomy_term->slug, 'title').'">'.$taxonomy_term->name.' <span class="label">'.$taxonomy_term->count.'</span></a> ';
    }
    $output .= '</span>';

    echo $output;

endwhile;​
于 2012-10-12T21:38:51.010 回答