2013-03-26 49 views

回答

1

你可以試試下面的代碼

foreach (get_posts('numberposts=-1') as $post) { 

      wp_set_object_terms($post_id, 'category_name', 'category'); 
    } 
1

使用WordPress的功能:

has_term:http://codex.wordpress.org/Function_Reference/has_term

和get_the_terms:http://codex.wordpress.org/Function_Reference/get_the_terms

它使用has_term(),這樣你就不會在不使用自定義標籤的帖子得到的錯誤是非常重要的。

get_the_terms()獲取當前帖子ID的所有術語,在循環中使用它。


例如:

<ul class="post-entry-meta"> 

<?php if(has_term('','your taxonomy')) 

{ 

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

foreach ($terms as $term) 

{echo '<li class="taxonomy-list">', $term->name , '</li>' ;} 

}?> 

</ul> 
1
<?php 
$custom_post_taxonomies = get_object_taxonomies('your_taxonomy_name'); 

if(count($custom_post_taxonomies) > 0) 
{ 
foreach($customPostTaxonomies as $tax) 
{ 
    $args = array(
      'orderby' => 'name', 
      'show_count' => 0, 
      'pad_counts' => 0, 
      'hierarchical' => 0, 
      'taxonomy' => $tax, 
      'title_li' => '' 
     ); 

    wp_list_categories($args); 
} 
} 
?> 

請您分類名稱替換 「your_taxonomy_name」。它工作得很好。

+0

這將列出所有類別。而不是分配給特定職位的人員。 – honk31

+0

我爲初學者創建了一個教程網站http://www.e2soft.com/blog&www.e2soft.com/forum – csehasib

相關問題