the_shortlink() - WordPress 函数参考中文文档

返回介绍

the_shortlink()

发布于 2017-09-11 字数3965 浏览 867 评论 0

the_shortlink( string $text = '',  string $title = '',  string $before = '',  string $after = '' )

Displays the shortlink for a post.


描述

Must be called from inside "The Loop"

Call like the_shortlink( __( ‘Shortlinkage FTW’ ) )


参数

$text

(string)
(Optional)
The link text or HTML to be displayed. Defaults to ‘This is the short link.’

Default value: ”

$title

(string)
(Optional)
The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.

Default value: ”

$before

(string)
(Optional)
HTML to display before the link.

Default value: ”

$after

(string)
(Optional)
HTML to display after the link.

Default value: ”


源代码

File: wp-includes/link-template.php

function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
	$post = get_post();

	if ( empty( $text ) )
		$text = __('This is the short link.');

	if ( empty( $title ) )
		$title = the_title_attribute( array( 'echo' => false ) );

	$shortlink = wp_get_shortlink( $post->ID );

	if ( !empty( $shortlink ) ) {
		$link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>';

		/**
		 * Filters the short link anchor tag for a post.
		 *
		 * @since 3.0.0
		 *
		 * @param string $link      Shortlink anchor tag.
		 * @param string $shortlink Shortlink URL.
		 * @param string $text      Shortlink's text.
		 * @param string $title     Shortlink's title attribute.
		 */
		$link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title );
		echo $before, $link, $after;
	}
}

更新日志

Version 描述
3.0.0 Introduced.

相关函数

Uses

  • wp-includes/l10n.php:
    __()
  • wp-includes/formatting.php:
    esc_url()
  • wp-includes/link-template.php:
    wp_get_shortlink()
  • wp-includes/link-template.php:
    the_shortlink
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/post-template.php:
    the_title_attribute()
  • wp-includes/post.php:
    get_post()
  • Show 2 more uses
    Hide more uses


User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Default Usage
    Displays link with “This is the short link.” as the text.

    
     <?php the_shortlink(); ?> 
    

    Output:

    This is the short link.

  2. Custom Text
    Displays link with the specified text.

    
    <?php the_shortlink( __( 'Shortlinkage FTW', 'textdomain' ) ); ?> 
    

    Output:
    Shortlinkage FTW

    Conditional HTML
    Displays link with prefix and suffix HTML that will appear only when the shortlink URL is available.

    
    <?php the_shortlink( 'short link', null, '<ul><li>', '</li></ul>' ); ?> 
    
    <a href="#" rel="nofollow">short link</a>
    

上一篇:the_search_query()

下一篇:the_tags()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!