0

我的 wordpress 页面中有 post_type = 投资组合,通过这段代码,我得到了每个帖子的类别:

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

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

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

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

4

1 回答 1

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....

于 2012-09-03T08:25:47.357 回答