get_page_template_slug

函式
get_page_template_slug ( $post = null )
引數
  • (int|WP_Post) $post Optional. Post ID or WP_Post object. Default is global $post.
    Required:
    Default: null
返回值
  • (string|false) Page template filename. Returns an empty string when the default page template is in use. Returns false if the post does not exist.
定義位置
相關方法
get_page_templatesget_page_templateget_paged_templateget_tag_templateget_date_template
引入
3.4.0
棄用
-

get_page_template_slug函式是WordPress的一個函式,用於檢索當前頁面模板的slug: 這個函式不接受任何引數: 該函式首先檢查當前頁面是否使用了自定義模板,如果是,則返回該模板的lug。如果該頁面沒有使用自定義模板,則返回一個空字串。

為一個給定的文章獲取特定的模板檔名。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_page_template_slug( $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$template = get_post_meta( $post->ID, '_wp_page_template', true );
if ( ! $template || 'default' === $template ) {
return '';
}
return $template;
}
function get_page_template_slug( $post = null ) { $post = get_post( $post ); if ( ! $post ) { return false; } $template = get_post_meta( $post->ID, '_wp_page_template', true ); if ( ! $template || 'default' === $template ) { return ''; } return $template; }
function get_page_template_slug( $post = null ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	$template = get_post_meta( $post->ID, '_wp_page_template', true );

	if ( ! $template || 'default' === $template ) {
		return '';
	}

	return $template;
}

常見問題

FAQs
檢視更多 >