Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
parent component visible in child pages as well
#6
(I haven't tested this, I hope it works :-))

Insert this code somewhere at the beginning of your template (or in your theme's functions.php file):

Code:
<?php
$myslugs = array('page1','page2','page3'); // <-- edit this

if (in_array(get_parent(0),$myslugs)) {
    $pageorparent = get_parent(0);
} elseif (in_array(get_page_slug(0),$myslugs) {
    $pageorparent = get_page_slug(0);
} else {
    $pageorparent = 'default';
}
?>

Now, to display the component:

Code:
<?php get_component('comp-'.$pageorparent); ?>

And to display the header image:

Code:
<img src="<?php get_site_url(); ?>data/uploads/header-<?php echo $pageorparent; ?>.png">

(change .png to your preferred image file extension)

- page1 and its child pages will display component comp-page1 and header image header-page1.png
- if a page is not in the list ($myslugs), component comp-default and image header-default.png will be displayed.
Reply


Messages In This Thread
parent component visible in child pages as well - by Carlos - 2012-04-23, 05:06:39



Users browsing this thread: 1 Guest(s)