最新公告
  • 欢迎您光临站盟网(原知事网),一个优质的网站源码基地、精品网站模板和插件。欢迎加入永久SVIP
  • WordPress函数wp_get_post_tags()用法 获取文章的标签Tags信息

    正文概述 知事网   2020-09-13 10:09   805

    描述:

    获取文章的标签Tags信息

    用法:

    <?php wp_get_post_tags( $post_id, $args ) ?>

    参数:

    $post_id
    
    (integer) (可选) The Post ID.
    
    默认值: 0
    
    $args
    
    (array) (可选) Overwrite the defaults. See wp_get_object_terms() for a list of valid options that can be passed.
    
    默认值: array

    示例:

    $t = wp_get_post_tags($post->ID);
    print_r($t);

    返回值:

    Array
    (
    [0] => stdClass Object
    (
    [term_id] => 4
    [name] => tag2
    [slug] => tag2
    [term_group] => 0
    [term_taxonomy_id] => 4
    [taxonomy] => post_tag
    [description] =>
    [parent] => 0
    [count] => 7
    )
    
    [1] => stdClass Object
    (
    [term_id] => 7
    [name] => tag5
    [slug] => tag5
    [term_group] => 0
    [term_taxonomy_id] => 7
    [taxonomy] => post_tag
    [description] =>
    [parent] => 0
    [count] => 6
    )
    
    [2] => stdClass Object
    (
    [term_id] => 16
    [name] => tag6
    [slug] => tag6
    [term_group] => 0
    [term_taxonomy_id] => 16
    [taxonomy] => post_tag
    [description] =>
    [parent] => 0
    [count] => 2
    )
    
    )

    源文件:

    /**
    * Retrieve the tags for a post.
    *
    * There is only one default for this function, called 'fields' and by default
    * is set to 'all'. There are other defaults that can be overridden in
    * {@link wp_get_object_terms()}.
    *
    * @since 2.3.0
    *
    * @param int $post_id Optional. The Post ID. Does not default to the ID of the
    * global $post. Defualt 0.
    * @param array $args Optional. Overwrite the defaults
    * @return array List of post tags.
    */
    function wp_get_post_tags( $post_id = 0, $args = array() ) {
    return wp_get_post_terms( $post_id, 'post_tag', $args);
    }

    站盟网 » WordPress函数wp_get_post_tags()用法 获取文章的标签Tags信息

    发表评论

    还没有评论,快来抢沙发吧!

    如需帝国cms功能定制以及二次开发请联系我们

    联系作者
    请选择支付方式
    ×
    支付宝支付
    微信支付
    余额支付
    ×
    微信扫码支付 0 元