返回介绍

the_shortlink()

发布于 2017-09-11 10:39:39 字数 3966 浏览 1003 评论 0 收藏 0

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

Displays the shortlink for a post.


description

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;
	}
}

更新日志

Versiondescription
3.0.0Introduced.

相关函数

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>
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文