get_page_link

函式
get_page_link ( $post = false, $leavename = false, $sample = false )
引數
  • (int|WP_Post) $post Optional. Post ID or object. Default uses the global `$post`.
    Required:
    Default: false
  • (bool) $leavename Optional. Whether to keep the page name. Default false.
    Required:
    Default: false
  • (bool) $sample Optional. Whether it should be treated as a sample permalink. Default false.
    Required:
    Default: false
返回值
  • (string) The page permalink.
定義位置
相關方法
_get_page_linkget_pagenum_linkget_tag_linkget_day_linkget_tag_feed_link
引入
1.5.0
棄用
-

get_page_link函式是一個WordPress的函式,通過它的ID檢索一個頁面的URL: 這個函式接受一個引數,即你要檢索的頁面的ID: 該函式返回該頁面的URL。

檢索當前頁面或頁面ID的固定連結。

尊重page_on_front。使用這個。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_page_link( $post = false, $leavename = false, $sample = false ) {
$post = get_post( $post );
if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
$link = home_url( '/' );
} else {
$link = _get_page_link( $post, $leavename, $sample );
}
/**
* Filters the permalink for a page.
*
* @since 1.5.0
*
* @param string $link The page's permalink.
* @param int $post_id The ID of the page.
* @param bool $sample Is it a sample permalink.
*/
return apply_filters( 'page_link', $link, $post->ID, $sample );
}
function get_page_link( $post = false, $leavename = false, $sample = false ) { $post = get_post( $post ); if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) { $link = home_url( '/' ); } else { $link = _get_page_link( $post, $leavename, $sample ); } /** * Filters the permalink for a page. * * @since 1.5.0 * * @param string $link The page's permalink. * @param int $post_id The ID of the page. * @param bool $sample Is it a sample permalink. */ return apply_filters( 'page_link', $link, $post->ID, $sample ); }
function get_page_link( $post = false, $leavename = false, $sample = false ) {
	$post = get_post( $post );

	if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
		$link = home_url( '/' );
	} else {
		$link = _get_page_link( $post, $leavename, $sample );
	}

	/**
	 * Filters the permalink for a page.
	 *
	 * @since 1.5.0
	 *
	 * @param string $link    The page's permalink.
	 * @param int    $post_id The ID of the page.
	 * @param bool   $sample  Is it a sample permalink.
	 */
	return apply_filters( 'page_link', $link, $post->ID, $sample );
}

常見問題

FAQs
檢視更多 >