在wordpress中发布类型类别

时间:2012-08-01 14:26:50

标签: wordpress

我的wordpress页面中有post_type =组合,使用此代码我得到每个帖子的类别:

$terms = get_the_terms( $post->ID, 'portfolio_category' );

foreach ( $terms as $term ) {
    $draught_links[] = $term->name;
}

$on_draught = join( ", ", $draught_links );

但它无法正常工作。它显示了当前帖子的类别以及之前的所有帖子。如何解决?

1 个答案:

答案 0 :(得分:3)

将此代码用于特定类别

<?php
global $post;
$args = array( 'numberposts' => 5, 'category' => 3 );


$myposts = get_posts( $args );
foreach( $myposts as $post ) :
setup_postdata($post); ?>

<?php the_title(); ?>
<?php the_content(); ?>

更改帖子和类别ID ....