您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
23. 获取文章所属的标签信息
发布时间:2023-03-14 18:11:40编辑:雪饮阅读()
首先就是我们将上篇的single.php修改成singular.php
然后新建single.php进行测试。
然后待测试文章的标签至少先要有2个吧
那么最后的single.php如:
<?php
/*
the_tags获取当前文章的标签列表,虽然在循环中,由于循环中不断覆盖post,所以可以用
第一个参数为前缀,是在整个tag列表的最前面
第二个参数是定界符,默认是“,”
第三个参数是后缀,是在整个tag列表的最后面
get_the_tag_list获取当前文档的标签列表,同the_tags,只是这里是返回html元素的那种标签列表,也可以在循环中使用,应也是同理
三个参数也是同样的
*/
?>
<?php if(have_posts()):?>
<?php while(have_posts()):the_post();?>
<div style="border:1px solid pink;">
<div style="display:flex;justify-content: center;">
<div style="border:1px solid red; width:90%;">
<p>文章所属标签信息 the_tags:<?php the_tags();?></p>
<p>文章所属标签信息 the_tags(前缀):<?php the_tags("<");?></p>
<p>文章所属标签信息 the_tags(定界符):<?php the_tags("<","|");?></p>
<p>文章所属标签信息 the_tags(后缀):<?php the_tags("<","|",">");?></p>
<p>文章所属标签信息 get_the_tag_list:<?php echo get_the_tag_list();?></p>
<p>文章所属标签信息 get_the_tag_list(前缀,定界符,后缀):<?php echo get_the_tag_list("<","|",">");?></p>
<p>文章所属标签的纯数据 get_the_tags:<?php print_r(get_the_tags());?></p>
<p>文章所属标签的纯数据 get_the_tags(遍历):<?php $tags=get_the_tags();?></p>
<?php foreach($tags as $tag):?>
<p style="text-indent:50px;">编号:<?php echo $tag->term_id;?></p>
<p style="text-indent:50px;">名称:<?php echo $tag->name;?></p>
<p style="text-indent:50px;">别名:<?php echo urldecode($tag->slug);?></p>
<p style="text-indent:50px;">标签归档页网址:<?php echo get_tag_link($tag);?></p>
<?php endforeach;?>
</div>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<p>对不起,暂时没有任何内容!</p>
<?php endif;?>
关键字词:标签