亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

顯示多個 Woocommerce 自定義分類法的術語

顯示多個 Woocommerce 自定義分類法的術語

PHP
胡說叔叔 2022-01-08 20:46:10
我需要來自三個自定義 Woocommerce 分類的術語的內爆列表,包括要在產品循環中顯示的分類名稱。我還需要能夠為每個分類顯示多個術語。但是,我只能讓它與一種分類法一起工作。而且我不知道如何顯示相應的分類名稱。我的自定義分類法是“藝術家”、“插畫家”和“作者”。這是我要完成的工作:羅伯特·道格拉斯(作者)、比爾·約翰斯頓(插畫家)、凱爾·麥克貝斯(藝術家)function list_author_terms() {    global $post;    $person = get_the_terms(get_the_ID(), 'authors', 'artists', 'illustrators');    if (    $person     && !is_wp_error(  $person )    ) {    @usort( $person, function ( $a, $b )    {    return strcasecmp(             $a->slug,            $b->slug        );    });    // Display your terms as normal    $term_list = [];    foreach ( $person as $term )        $term_list[] = '<a href="' . get_term_link( $term ) . '"class="author rsc-tp">' . esc_html( $term->name ) . '<span class="attribute"> (Author)</span> </a>';       $term_names[] = $term->name;     echo implode( ', ', $term_list);        echo '<br>';    }}
查看完整描述

1 回答

?
一只萌萌小番薯

TA貢獻1795條經驗 獲得超7個贊

添加以下代碼片段以完成您的任務 -


add_action( 'woocommerce_after_shop_loop_item', 'list_author_terms', 6 );

function list_author_terms(){

    $taxonomies = array( 'authors', 'artists', 'illustrators' );

    $pro_list_terms = array();

    foreach ( $taxonomies as $taxonomy ) {

        $term_obj_list = get_the_terms( get_the_ID(), $taxonomy );

        $tax_obj = get_taxonomy( $taxonomy );

        if( $term_obj_list && ! is_wp_error( $term_obj_list ) ){

            foreach ( $term_obj_list as $term ) {

                $link = get_term_link( $term, $taxonomy );

                $pro_list_terms[] = '<a href="' . esc_url( $link ) . '" class="author rsc-tp">' . $term->name . ' (' .$tax_obj->labels->singular_name . ')</a>';

            }

        }

    }

    echo join( ', ', $pro_list_terms );

}


查看完整回答
反對 回復 2022-01-08
  • 1 回答
  • 0 關注
  • 177 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號