FreeAgent Posted September 25, 2015 Share Posted September 25, 2015 I'm just getting started with ProcessWire using the Default Profile. Thus far everything is working out great even with my very limited PHP knowledge. Right now I'm trying to wiggle a basic blog into my setup. I've setup a page called blog, and I have 2 test post pages as children of blog. In the sidebar on blog post pages only I want to show social sharing elements. I'm currently using the following code... if($page->rootParent->hasChildren) { echo "social share stuff";} I have 2 problems with this. 1. This echo will display on both the parent and its children. I only want to echo on the child pages. 2. The code above will echo on all parents that have children. I only want this echo to trigger on children of blog. Can anyone help me out with this please? Link to comment Share on other sites More sharing options...
Pauline Posted September 25, 2015 Share Posted September 25, 2015 Hi FreeAgent, If I get you right, then you have a page with name "blog" under the homepage. If the current page is a child of "blog", you want to display the shares, right? if ($page->rootParent->name == "blog") { echo "social share stuff"; } // if this doesn't work, you can try additionally if ($page->rootParent->name == "blog" && $page->name != "blog") { echo "social share stuff"; } PS: the editor button with this sign: <> opens a box for code. 2 Link to comment Share on other sites More sharing options...
FreeAgent Posted September 25, 2015 Author Share Posted September 25, 2015 That worked perfectly, Pauline! Thank you so much for your help. I need to get better with PHP. Link to comment Share on other sites More sharing options...
FreeAgent Posted September 25, 2015 Author Share Posted September 25, 2015 After taking another look I still have a problem. I don't want the echo to trigger on blog. I want it to trigger on blogs children only. In a nutshell I'm using the defult profile. This profile uses _main.php as its central template. I'm trying to write some code that will only display the comments section on blog entry pages. These pages are the children of blog. Link to comment Share on other sites More sharing options...
FreeAgent Posted September 25, 2015 Author Share Posted September 25, 2015 I figured it out. If anyone else is trying to do this here was the very simple change to get it working... if ($page->parent->name == "blog") { echo "social share stuff"; } 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now