Last active
August 29, 2015 13:57
-
-
Save germanny/9399399 to your computer and use it in GitHub Desktop.
why does this fail?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 } | |
*/ | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your
page.php
can be completely cleaned up by using both theis_tree
andis_child
functions from here: https://gist.github.com/ericrasch/4723316Also, you should make your
include_once(CHILD_SS_DIR . '/
uniform to use the template path as you did in line 9: https://gist.github.com/germanny/9399399#file-page-php-L9