2012-08-01 103 views
0

我有post_type =投资组合在我的WordPress页面,并使用此代码我得到的每一个职位的类别:邮政型类别中的WordPress

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

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

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

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

+1

可能需要多一点的上下文来回答这个问题。例如,这个代码是在“The Loop”还是在它之外? – Chaser324 2012-08-01 14:41:58

+1

,如果它在一个循环内,考虑在'foreach($ terms as $ term)之前初始化'$ draught_links = array()'' – Mwayi 2012-08-01 14:47:20

+0

@ user622018这似乎是一个很可能的原因。 – Chaser324 2012-08-01 14:49:59

回答

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(); ?> 

Chnage职位和类别ID的数量....

相关问题