標籤: 分類名稱
正在查看 5 個帖子:1-5 (共 5 個帖子)
-
作者帖子
-
請問自定義內容,有 2 級分類,在某個頁面的詳情頁,怎麼顯示該頁面的頂級分類名稱?
在循環內容裏,顯示該頁面的頂級分類名稱。是用 get_the_terms( int|WP_Post $post, string $taxonomy ) ??
因為不懂代碼,如果不復雜的話,能否提供代碼?
今天商城訂單有點多,需要人手處理下,忙完給你找找相關説明。
看下這個是不是你要的那種
https://wordpress.stackexchange.com/questions/45083/get-the-first-post-term
下面是
get_the_terms
的官方示例,https://developer.wordpress.org/reference/functions/get_the_terms/
不是很清楚你説的自定義內容是不是指自定義文章類型 CPT 如果是的話你可以用一些熱門的開發工具來做的。
非常感謝工作這麼晚,還沒休息,還在幫忙解答。
我的諮詢是:
如果在文章有二級分類,在文章詳細頁,如果獲取該篇文章的頂級 (父級) 分類名稱?
剛剛通過論壇搜索,已經找到解答了,非常感謝哈。
可以獲取文章或自定義內容,詳細頁的頂級分類名稱或子類名稱。$taxonomy = 'category'; //如果是自定義內容,這裏修改自定義分類名稱。 // Get the term assigned to post. $post_term = wp_get_object_terms( $post->ID, $taxonomy); if ( ! empty( $post_term ) && ! is_wp_error( $post_term ) ) { // parent category object $parent = get_term($post_term[0]->parent, $taxonomy); echo ' <div class="cat-links"> '; get_template_part('images/inline', 'picto-actu.svg'); // Display post categories. echo '<a href="'. get_term_link($parent->term_id,$taxonomy).'">'.$parent->name.'</a> >'; echo '<a href="'. get_term_link($post_term[0]->term_id,$taxonomy).'">'.$post_term[0]->name.'</a> >'; echo ' </div> '; }
-
作者帖子
正在查看 5 個帖子:1-5 (共 5 個帖子)
- 哎呀,回覆話題必需登錄。