Yesterday Ian came up with a nice question:
Can you make sidebar registration dependent on a template being activ? Like, front page sidebars only registered if front-page.php in use?
He’s not talking ’bout displaying a certain sidebar on a page that uses a certain page template. That’s too easy
Here’s my first attempt to solve this problem using a new conditional tag:
function is_pagetemplate_active($pagetemplate = '') {
global $wpdb;
$sql = "select meta_key from $wpdb->postmeta where meta_key like '_wp_page_template' and meta_value like '" . $pagetemplate . "'";
$result = $wpdb->query($sql);
if ($result) {
return TRUE;
} else {
return FALSE;
}
}
2 Kommentare
Chris, Thanks for this code! I was thinking about incorporating something similar to my own project, but have not gotten around to it yet. I found your function from twitter and tested it out. Works great for me on 2.9. Nice work!!!
Incredible! I saw this tweet appear and only hours later a viable solution!
Thanks for this!