parent component visible in child pages as well - Printable Version +- GetSimple Support Forum (http://get-simple.info/forums) +-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3) +--- Forum: Scripts & Components (http://get-simple.info/forums/forumdisplay.php?fid=11) +--- Thread: parent component visible in child pages as well (/showthread.php?tid=2996) |
parent component visible in child pages as well - andyash - 2012-03-27 1. I want to use the parent page's sidebar component for all of its child pages. What code do I use? 2. Also if a page does not have a component is there a code I can use to direct that page to a different component-less template? parent component visible in child pages as well - Carlos - 2012-03-28 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'); ?> But here's another more complete and flexible solution: Code: <?php component-x is the default component, if the current page is not page-1, page-2 or page-3 or their children. parent component visible in child pages as well - andyash - 2012-03-28 Thanks. This works great. Can I apply the same principle for parent header image displaying in child pages as well? What code do I use? parent component visible in child pages as well - Carlos - 2012-03-29 I can do another piece of code (different approach) to be used for both components and header image, if you don't mind using names like e.g. component comp-page1 and image header-page1.png for page1 and its child pages. (This would make it simpler.) parent component visible in child pages as well - andyash - 2012-04-23 Carlos Wrote:I can do another piece of code (different approach) to be used for both components and header image, if you don't mind using names like e.g. component comp-page1 and image header-page1.png for page1 and its child pages. (This would make it simpler.) Could you do that please? Always a sucker for trying out more and simpler ways to get the desired result. parent component visible in child pages as well - Carlos - 2012-04-23 (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 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. |