如何在WordPress中获取最新的标签

我想在WordPress网站中获取最新(最新)标签。我搜索了很多, 但没有找到任何解决方案。

请帮忙

谢谢


#1


$args = array(
    'number' => 1, 'order' => DESC
);
$tags = get_tags( $args );

foreach ( $tags as $tag ) {
    $tag_link = get_tag_link( $tag->term_id );  
    $html = "<a href='{$tag_link}' title='{$tag->name}' class='{$tag->slug}'>";
    $html .= "{$tag->name}</a>";
    echo $html;
}

编辑以显示最新标签。有关详细信息, 请参见评论。

参考:http://codex.wordpress.org/Function_Reference/get_tags


#2


我知道, 你需要获取wordpress标签名称, 我将编写一个非常简单的脚本来显示tag_name

<?php 

 // Get value from wordpress get_tags() function and stored in $your_tag variable
 $your_tag = get_tags();

 // Check if has tag          
 if( $your_tag ){

 // Fetch data from array argument using foreach loop
 foreach( $your_tag as $tag_single ) {

     echo '<li><a href="'. esc_url( get_tag_link( $tag_single->term_id ) ) .'">'." $tag_single->name ".'</a></li>'; 

   }        
}

?>

有关更多信息, 请检查

https://codex.wordpress.org/Function_Reference/get_tags

来源:

https://www.srcmini02.com/65349.html

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?