帖子列表及其分类

时间:2017-01-04 21:31:01

标签: wordpress list taxonomy

我想显示wordpress帖子类型的帖子列表,但我不知道如何显示与帖子相关的分类术语。 我的代码:

<ul class="list-group"> 
    <?php
    $args = array(
        'post_type' => 'faq',
        'post_status' => 'publish',
        'orderby'          => 'date',
        'order'            => 'DESC',
        'posts_per_page' => 5,

    )
    ;$myposts = get_posts( $args );
    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
        <li class="list-group-item">
        <span class="label label-default">xxxxx taxonomy xxxxxx</span>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </li>
    <?php endforeach; 
    wp_reset_postdata();?>
    </ul>
你能帮帮我吗?

2 个答案:

答案 0 :(得分:0)

<?php query_posts(array('post_type'=>'faq', 'posts_per_page'=>5, 'order' => 'DESC', )); ?>
    <?php if(have_posts()) { while(have_posts()) {  the_post();?>   
    <div class="col-md-6 col-sm-6">
        <?php if ( has_post_thumbnail() ) {?>
            <div class="blog_image">
                <?php the_post_thumbnail( 'full' ); ?>
            </div>
        <?php } else{ ?>
        <?php }?>
        <div class="entry-content">
            <h3 class="blog-title">
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </h3>
            <span class="post-date"><?php echo get_the_date('d. M Y'); ?></span>
            <p><?php echo wp_trim_words( get_the_content(), 50, ' (...)' );?></p>
        </div>
    </div>
<?php }
    }
    wp_reset_query(); 
?>

 for image display <?php the_post_thumbnail( 'full' ); ?> 
 for title display <?php the_title_attribute(); ?> for title display 
 for content display <?php the_content();?> 

根据需要更改HTML

答案 1 :(得分:0)

<?php
/* FIRST
 * Note: This function only returns results from the default “category” taxonomy. For custom taxonomies use get_the_terms().
 */
$categories = get_the_terms( $post->ID, 'taxonomy' );
// now you can view your category in array:
// using var_dump( $categories );
// or you can take all with foreach:
foreach( $categories as $category ) {
    echo $category->term_id . ', ' . $category->slug . ', ' . $category->name . '<br />';
}
相关问题