2012-03-28, 08:06:12
Simple way just for one component for a parent and its subpages:
For several pages and components you could repeat this line.
But here's another more complete and flexible solution:
component-x is the default component, if the current page is not page-1, page-2 or page-3 or their children.
Code:
<?php if (get_parent(0)=='page' or get_page_slug(0)=='page') get_component('componentname'); ?>
But here's another more complete and flexible solution:
Code:
<?php
$pagecomp = array(
'page-1' => 'component-a',
'page-2' => 'component-b',
'page-3' => 'component-c' // no comma in last one
);
$thecomp = '';
foreach($pagecomp as $key=>$value) {
if (get_parent(0)==$key or get_page_slug(0)==$key) {
$thecomp = $value;
break;
}
}
if ($thecomp != '') {
get_component($thecomp);
} else {
get_component('component-x'); // for pages/parents that are not in the array
}
?>
component-x is the default component, if the current page is not page-1, page-2 or page-3 or their children.