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。如果该页面没有使用自定义模板,则返回一个空字符串。

为一个给定的文章获取特定的模板文件名。

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
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-05 15:32:55

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: