0
votes

So I want to apply two separate templates, to two different types of pages (not posts). Both page types are children pages.

The template 'exhibition-template.php' is applied to all pages that are children of the 'archive' page. This works! I do this with a function in functions.php that tests to see if a page is a child of 'archive', then use that function in page.php to apply the template:

//////////////////////////////////////////////
function is_archivechild() {

// Set up the objects needed
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'posts_per_page' => '-1'));

// Get the page as an Object
$archive = get_page_by_title('archive');

// Filter through all pages and find archive's children
$archive_children = get_page_children( $archive->ID, $all_wp_pages );

if ($archive_children > 0){
return true;
}
else{
return false;
}
}
//////////////////////////////////////////////

And using it in page.php:

//////////////////////////////////////////////
elseif ( is_archivechild() ) {/*a function made up in functions.php, tests if it is a of archive*/
get_template_part( 'exhibition-template' );
get_template_part( 'normalfooter' );
}
//////////////////////////////////////////////

The problem is when I write the function a second time with new variables, and try to implement it in the exact same way except for applying 'artist-template.php' to children pages of 'artists', nothing changes, in fact it still applies 'exhibition-template.php' no matter what.

//////////////////////////////////////////////
function is_artistschild() {

// Set up the objects needed
$artist_query = new WP_Query();
$all_wp_pages = $artist_query->query(array('post_type' => 'page', 'posts_per_page' => '-1'));

// Get the page as an Object
$artists = get_page_by_title('artists');

// Filter through all pages and find artists's children
$artists_children = get_page_children( $artists->ID, $all_wp_pages );

if ($artists_children > 0){
return true;
}
else{
return false;
}
}
//////////////////////////////////////////////
elseif ( is_artistchild() ) {/*a function made up in functions.php, tests if it is a CHILD page, aka an exhibition*/
get_template_part( 'artist-template' );
get_template_part( 'normalfooter' );
}
//////////////////////////////////////////////

Whaaaaat the hell is going on?!?!? much thanks!

1
ok can you try change archive name of the page to another name ? Like "Test page" ??Tasos Fel
I tried that, no luck. I feel like the issue may be in the order of the if statement in my pages.php file, re-arranging the 'else ifs' cause it to break,Connor Crawford

1 Answers

0
votes

You can write inside page.php the above:

<?php global $post;
      $page = get_page_by_title( 'archive' ); // page title  , Archive in your case . Try an alternative page name.

      $page_parent_ID=$page->ID; 
?>

<?php if ($post->post_parent == $page_parent_ID) {
get_template_part( 'exhibition-template' ); // you name of template you want to appear

 } 
 ?>