用wordpress做网站,文章页面如何调用当前页面标签,下面web建站小编给大家介绍一下get_the_tags的使用方法!
get_the_tags()函数介绍
get_the_tags( int $post_id ) //$post_id(int):(必填)文章的 ID。
tags标签调用方法在wp-includes/category-template.php
function get_the_tags( $post_id = 0 ) {
$terms = get_the_terms( $post_id, 'post_tag' );
return apply_filters( 'get_the_tags', $terms );
}
get_the_tags()函数使用介绍
1、输出当前文章第一个标签
$post_tags = get_the_tags();
if ( $post_tags ) {
echo $post_tags[0]->name;
}
2、输出当前文章所有标签
$post_tags = get_the_tags();
if ( $post_tags ) {
foreach( $post_tags as $tag ) {
echo $tag->name . ', ';
}
}
3、显示带有链接和自定义分隔符的文章标签
function show_tags(){
$post_tags = get_the_tags();
$separator = ' | ';
if (!empty($post_tags)) {
foreach ($post_tags as $tag) {
$output .= '<a href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a>' . $separator;
}
return trim($output, $separator);
}
}
4、在下拉列表中显示文章的标签
<?php
function dropdown_tags(){
echo '<select name="tag" id="tag" class="postform">';
foreach ( get_the_tags() as $tag ) {
echo '<option value="' . $tag->name . '">' . $tag->name . "</option>\n";
}
echo '</select>';
}
?>
<h2><?php _e( 'Tags:', 'textdomain' ); ?></h2>
<form id="tags-select" class="tags-select" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
<?php dropdown_tags(); ?>
<input type="submit" name="submit" value="view" />
</form>
小半WordPress AI助手:开源免费的AI插件,为WordPress网站注入智能内容创作能力
WordPress ai助手:为 WordPress 用户提供集成多种 AI 模型的功能
wordpress获取当前文章最后一个tags标签(不带链接)
上面是“wordpress文章页面显示标签代码介绍(标签函数使用方法)”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2386.html
workflows工作流
一只黑色章鱼ComfyUI工作流
森林里一只空灵的犀鸟ComfyUI工作流
一辆老式灵车在黑暗中从雾中出现ComfyUI工作流
一个黑人在森林中穿着折纸的衣服ComfyUI工作流
一棵白色心形流苏树comfyui工作流
海中一头鲸鱼ComfyUI工作流
穿着蘑菇帽的小蚂蚁探险家ComfyUI工作流
《翅膀之王:鸡的团契》海报ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

数字滚动效果(兼容IE6/IE8)
2023年程序猿如何给自己开启一场烟花盛会
纯css制作卡通头像(随鼠标转头)
js+css3做一个灯泡开灯关灯效果
利用css3做一个动态loading效果
日历设置每个月颜色都不一样
利用html5+css3实现滚雪球效果(附代码)
js实现下雪特效











