Is a certain page template active?

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;
	}
}
Dieser Eintrag wurde veröffentlicht in WordPress und getagged , , . Bookmarken: Permanent-Link. Kommentieren oder ein Trackback hinterlassen: Trackback-URL.

2 Kommentare

  1. Erstellt am 19. Dezember 2009 um 16:39 | Permanent-Link

    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!!!

  2. Erstellt am 19. Dezember 2009 um 19:37 | Permanent-Link

    Incredible! I saw this tweet appear and only hours later a viable solution!

    Thanks for this!

Ihr Kommentar

Ihre E-Mail wird niemals veröffentlicht oder verteilt. Benötigte Felder sind mit * markiert

*
*

Du kannst diese HTML Tags und Attribute verwenden: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>