Products
GG网络技术分享 2025-03-18 16:13 0
WordPress模板标签the_tags用于在文章页输出标签链接
the_tags( string $before = null, string $sep = ‘, ‘, string $after = ” )
$before
字符串值,默认值:null
在标签链接前显示的文本。
$sep
字符串值,默认值:,
在每个标签链接之间显示的文本。
$after
字符串值,默认为空
在标签链接后显示的文本。
使用函数时最好认真看看源码,顺便学习,对于制作wordpress主题有好处
the_tags()函数位于:wp-includes/category-template.php
相关函数:
get_tag()
get_tag_link()
get_tags()
get_the_tag_list()
get_the_tags()
is_tag()
single_tag_title()
tag_description()
wp_generate_tag_cloud()
wp_tag_cloud()
在给我们的博客更新文章时,大多数人应该会给文章添加一些TAG标签,文章添加TAG标签也是我们做WordPress优化必不可少的一项,但是如果每一篇文章的关键字标签都要手动添加链接,那也太麻烦了。
今天wp自学笔记给大家分享一篇自动给文章添加TAG标签的WordPress教程,其实也非常的简单只需要把下面的代码添加到主题的functions.php里即可。
//自动为文章添加标签add_action(\\\'save_post\\\', \\\'auto_add_tags\\\');function auto_add_tags(){$tags = get_tags( array(\\\'hide_empty\\\' => false) );$post_id = get_the_ID();$post_content = get_post($post_id)->post_content;if ($tags) {foreach ( $tags as $tag ) {// 如果文章内容出现了已使用过的标签,自动添加这些标签if ( strpos($post_content, $tag->name) !== false)wp_set_post_tags( $post_id, $tag->name, true );}}}
上文分享了给文章自动添加TAG标签方法,那么如果我们希望TAG标签能够自动链接到对应的文章该怎么实现呢?
可以看看这篇文章,有详细的讲解:WordPress优化之给文章标签自动添加内链
扫码关注wpwp自学笔记
精选优质免费WordPress主题模板,分享最新WordPress实用建站教程!
记住我们的网址:ztJun.com
Demand feedback