Issue
Here is a screenshot:
I want to catch a specific page template and show meta box according the specific page template. I have tried to with it:
$pageTemplate = get_post_meta($post->ID, '_wp_page_template', true);
but is not working.
Solution
Add the following code to functions.php
:
add_filter('template_include', 'var_template_include', 1000);
function var_template_include($t) {
$GLOBALS['current_theme_template'] = basename($t);
return $t;
}
function get_current_template() {
if (isset($GLOBALS['current_theme_template'])) {
return $GLOBALS['current_theme_template'];
} else {
return false;
}
}
You'll then be able to do the following:
$pageTemplate = get_current_template();
Answered By - Hillel Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.