标签: 分类名称
正在查看 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 个帖子)
- 哎呀,回复话题必需登录。