用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工作流
stvmccrr风格的玫瑰花ComfyUI工作流
一个精致透明的朱红色水晶凤凰
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

利用css绘画棋盘布局(象棋)
HTML5 Canvas 刻度尺
利用css3做一个动态loading效果
js导出excel插件(兼容mac电脑Numbers表格)
利用canvas画几个好玩的星云物种
3d文字360度旋转
jquery做一个漂亮挂墙动态时钟
css3结合svg做一个动态广告











