返回介绍

_get_page_link()

发布于 2017-09-11 13:24:20 字数 3099 浏览 915 评论 0 收藏 0

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_get_page_link( int|WP_Post $post = false,  bool $leavename = false,  bool $sample = false )

Retrieves the page permalink.


description

Ignores page_on_front. Internal use only.


参数

$post

(int|WP_Post) (Optional) Post ID or object. Default uses the global $post.

Default value: false

$leavename

(bool) (Optional) Whether to keep the page name.

Default value: false

$sample

(bool) (Optional) Whether it should be treated as a sample permalink.

Default value: false


返回值

(string) The page permalink.


源代码

File: wp-includes/link-template.php

function _get_page_link( $post = false, $leavename = false, $sample = false ) {
	global $wp_rewrite;

	$post = get_post( $post );

	$draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );

	$link = $wp_rewrite->get_page_permastruct();

	if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) {
		if ( ! $leavename ) {
			$link = str_replace('%pagename%', get_page_uri( $post ), $link);
		}

		$link = home_url($link);
		$link = user_trailingslashit($link, 'page');
	} else {
		$link = home_url( '?page_id=' . $post->ID );
	}

	/**
	 * Filters the permalink for a non-page_on_front page.
	 *
	 * @since 2.1.0
	 *
	 * @param string $link    The page's permalink.
	 * @param int    $post_id The ID of the page.
	 */
	return apply_filters( '_get_page_link', $link, $post->ID );
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-includes/link-template.php: home_url()
  • wp-includes/link-template.php: _get_page_link
  • wp-includes/link-template.php: user_trailingslashit()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post.php: get_page_uri()
  • wp-includes/post.php: get_post()
  • wp-includes/class-wp-rewrite.php: WP_Rewrite::get_page_permastruct()
  • Show 2 more uses Hide more uses

Used By

  • wp-includes/link-template.php: get_post_comments_feed_link()
  • wp-includes/link-template.php: get_page_link()
  • wp-includes/link-template.php: get_attachment_link()

User Contributed Notes

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

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

发布评论

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