Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
parent component visible in child pages as well
#2
Simple way just for one component for a parent and its subpages:
Code:
<?php if (get_parent(0)=='page' or get_page_slug(0)=='page') get_component('componentname'); ?>
For several pages and components you could repeat this line.

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.
Reply


Messages In This Thread
parent component visible in child pages as well - by Carlos - 2012-03-28, 08:06:12



Users browsing this thread: 1 Guest(s)