admin管理员组文章数量:1130349
On search results pages I would like to show a tag list collected from other posts that are listed for the seach result.
// same tag should not be listed twice
And for the taxonomy pages again; tags of other post that are listed for the current tag.
I tried some experiments with get_the_tags(array(post ids)) but couldn't make it work.
Thank you,
On search results pages I would like to show a tag list collected from other posts that are listed for the seach result.
// same tag should not be listed twice
And for the taxonomy pages again; tags of other post that are listed for the current tag.
I tried some experiments with get_the_tags(array(post ids)) but couldn't make it work.
Thank you,
Share Improve this question asked Apr 8, 2017 at 7:38 boorockboorock 618 bronze badges1 Answer
Reset to default 0You can use simple solution below. You need to use this function in the loop. You can collect tags/categories in an array or show tags/categories under the posts.
$terms = get_the_terms( get_the_ID(), 'category' );
if ( $terms && ! is_wp_error( $terms ) ) :
$catlinks = array();
foreach ( $terms as $term ) {
$catlinks[] = $term->name;
}
$catso = join( ", ", $catlinks );
?>
<p class="list-of-cats">
<?php printf( esc_html__( 'Categories: <span>%s</span>', 'textdomain' ), esc_html( $catso ) ); ?>
</p>
On search results pages I would like to show a tag list collected from other posts that are listed for the seach result.
// same tag should not be listed twice
And for the taxonomy pages again; tags of other post that are listed for the current tag.
I tried some experiments with get_the_tags(array(post ids)) but couldn't make it work.
Thank you,
On search results pages I would like to show a tag list collected from other posts that are listed for the seach result.
// same tag should not be listed twice
And for the taxonomy pages again; tags of other post that are listed for the current tag.
I tried some experiments with get_the_tags(array(post ids)) but couldn't make it work.
Thank you,
Share Improve this question asked Apr 8, 2017 at 7:38 boorockboorock 618 bronze badges1 Answer
Reset to default 0You can use simple solution below. You need to use this function in the loop. You can collect tags/categories in an array or show tags/categories under the posts.
$terms = get_the_terms( get_the_ID(), 'category' );
if ( $terms && ! is_wp_error( $terms ) ) :
$catlinks = array();
foreach ( $terms as $term ) {
$catlinks[] = $term->name;
}
$catso = join( ", ", $catlinks );
?>
<p class="list-of-cats">
<?php printf( esc_html__( 'Categories: <span>%s</span>', 'textdomain' ), esc_html( $catso ) ); ?>
</p>
本文标签: searchRelated Tags Concept
版权声明:本文标题:search - Related Tags Concept 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749147214a2323197.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论