2012-08-01 34 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的數量....

相關問題