如何从自定义分类法中获取最后一个术语?

时间:2015-07-31 11:33:54

标签: php wordpress taxonomy term

我尝试使用此代码显示最后一个(最后一个=最近添加的)之前的术语,以自动显示上一期出版物的链接:

$args = array( 'hide_empty=0' );
$terms = get_terms( 'issue', 'orderby=id&order=DESC' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
    $count = count( $terms );
    $i = 0;
    $term_list = '';
    foreach ( $terms as $term ) {
        $i++;
        $term_list .= '<a href="' . get_term_link( $term ) . '" title="' . sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) . '">(' . $term->name . ')</a>';
        if ( $count != $i ) {
            $term_list .= ' , ';
        }
        else {
            $term_list .= '';
        }
    }
$result = implode(",", array_slice(str_word_count($term_list, 1), 0, -1));
    echo $result;

但它不起作用。它显示

a,href,http,localhost,,issue,vol-,-no-,title,View,all,post,filed,under,Vol,-,No,‌​Vol,-,No,a,a,href,http,localhost,i,issue,vol-,-no-,title,View,all,post,filed,unde‌​r,Vol,-,No,Vol,-,No,a,a,href,http,localhost,i,issue,title,View,all,post,filed,und‌​er,a,a,href,http,localhost,,issue,title,View,all,post,filed,under

有什么建议吗?

0 个答案:

没有答案