germanny
3/6/2014 - 8:52 PM

why does this fail?

why does this fail?

<?php 
get_header();

// check and apply page template if it's one of these pages
if ( is_front_page() ) : include_once('templates/tmpl-home.php');
elseif ( get_id_by_page_name('subjects') == $post->post_parent ) : include_once('templates/tmpl-subjects-child.php');
elseif ( 'subjects' == get_absolute_ancestor($post->ID) && !is_page('subjects') ) : include_once('templates/tmpl-subjects-grandchild.php');
elseif ( get_id_by_page_name('schools') == $post->post_parent ) : include_once('templates/tmpl-schools-child.php');
elseif ( is_page('school-profile') ) : include_once(CHILD_SS_DIR . '/templates/tmpl-schools-child.php');

// else use regular page template

else {
  // do stuff
}
?>
<?php
/**
 * Get a Page's ID by post_name (slug)
 */
function get_id_by_page_name($post_name) {
	global $wpdb;
	$post_name_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$post_name."'");
	if ( ( $post_name_id !== NULL ) || ( $post_name_id !== '0' ) ) {
		return $post_name_id;
	}
}

/* use like this:
 *
 * if ( get_id_by_page_name('schools') == $post->post_parent ) { do stuff }
 */ 
?>