在wordpress中发布时限制结果

时间:2014-11-01 14:54:22

标签: wordpress

我对wordpress很新,所以请原谅我以前已经回答过,因为我在搜索时无法找到它。

我想调出列出广告的类别,但将结果限制为只有'。

这是我到目前为止所做的:

<?php if ( $post->post_type == 'post' ) the_category(', '); else echo get_the_term_list( $post->ID, APP_TAX_CAT, '', ', ', ''); ?>

那么我该怎样编辑它才能将结果限制在3个类别。

1 个答案:

答案 0 :(得分:0)

get_the_term_list只是一个辅助函数,假设您希望输出与帖子关联的所有术语作为标记。如果您想要控制预先返回的字词,请改用get_terms

另外,不要在一行上编写所有PHP。这种可怕的做法,让任何必须继承你的代码的人都想踢小狗。

<?php
if ( $post->post_type == 'post' ){
    the_category(', ');
}
else{
    $terms = get_terms(APP_TAX_CAT, array('number'=>3, 'fields'=>'names'));
    echo implode(', ', $terms);
}
?>