
求當前分類,試了很多函數。最後下面才有用。
$thisCat = get_category(get_query_var('cat'),false);
pre($thisCat);
因為點產品時,而產品是總類,它下面並沒有 post,那這時用別的就取不出產品。
----
如果用 pre(get_the_category()); 時,會返當前有文章的分類。
不管是第一種還是第二種,都會返回對象,再 pre 後 取得 term_id 後,再用
<?php pre(get_term( term_id,'category')) ?> 去得到上一級。最終 parent 為 0 時,就是最頂級。
有了最頂級後,就可以調不同的分類列表了,這是取最頂級的目的。
get_template_part( 'content-tvcatproduct', get_post_format() );
------
參考:
if ( 'tvproduct' == get_post_type() ) // 這是按內容類型,對於企業站來説,並不一定要去建內容類型。
get_template_part( 'content-tvcatproduct', get_post_format() );