- This topic has 25 replies, 4 voices, and was last updated 8 years, 6 months ago by Tom.
-
AuthorPosts
-
September 30, 2015 at 11:23 am #141007David
I wish to insert a hook for Page Header.
1. Insert Page Title into Page Header Content metabox
2. Only show child page of Unique Parent ID.I have the parent ID. So how do I get the child pages to show instead of the parent page.
<?php if ( is_page(201) ) : ?> <div class="page-header-content generate-page-header generate-content-header"><div class="inside-page-header-container inside-content-header grid-container grid-parent "> <header style="display:block;" class="entry-header"> <h1 class="entry-title" itemprop="headline">TESTING HEADERS FOR CHILDREN CITIES</h1> </header></div></div> <?php endif; ?>
I hope this communicates.
Thanks!
September 30, 2015 at 11:47 am #141015TomLead DeveloperLead DeveloperHi David,
So you want that block to show up only on child pages of your 201 parent ID?
September 30, 2015 at 11:59 am #141018bdbrownThe first answer on this StackOverflow post might help.
September 30, 2015 at 12:24 pm #141022David@Tom. That is correct.
Thanks!
September 30, 2015 at 8:08 pm #141097TomLead DeveloperLead Developerbdbrown linked to a post with the answer above: https://generatepress.com/forums/topic/page-header-for-unique-child-pages/#post-141018
That should work π
September 30, 2015 at 11:51 pm #141108DavidThanks I will put that in action.
@bdbrown Thanks again!October 1, 2015 at 11:08 am #141193bdbrownYou’re welcome π
October 1, 2015 at 11:10 am #141194DavidThis is link and instructions worked well.
I added this to the functions.php within the Child Theme:
function is_page_child($pid) {// $pid = The ID of the page we're looking for pages underneath global $post; // load details about this page $anc = get_post_ancestors( $post->ID ); foreach($anc as $ancestor) { if(is_page() && $ancestor == $pid) { return true; } } if(is_page()&&(is_page($pid))) return true; // we're at the page or at a sub page else return false; // we're elsewhere };
I added this within GP Hooks – “After Header”:
<?php if (is_page_child(201) ) : ?> <div class="page-header-content generate-page-header generate-content-header"><div class="inside-page-header-container inside-content-header grid-container grid-parent "> <header style="display:block;" class="entry-header"> <h1 class="titlebar"><?php the_title(); ?></h1> </header></div></div> <?php endif; ?>
Now I have a new result that I can’t seem to figure out how to adjust. How do I get the “Title” to appear within the “Page Header Content”?
Cheers!
October 1, 2015 at 11:30 am #141200DavidHere is the URL for review.
October 1, 2015 at 1:12 pm #141237TomLead DeveloperLead DeveloperAwesome, thanks for posting the code! π
October 1, 2015 at 1:23 pm #141243bdbrownHi David. I’m not sure what you’re trying to accomplish. It appears that on your Cities parent page, and all the city child pages, the page header has now been duplicated because the page header code has been added to the “After Header” hook.
October 1, 2015 at 4:44 pm #141279David@bdbrown Thanks for the followup. It is duplicating. And yes, it is place in the “After Header” hook.
I want the Title to appear over the Page Header Image. Each “City Title” get its own image. It’s kind of working that way now.
How do I place the hook so it appears correctly?
Thanks for your expertise.
October 1, 2015 at 8:43 pm #141321bdbrownWhat I think I understand is that you want the page title to appear on top of the page header, which contains a unique image for each child page. So, if it’s “kind of working that way now”, what about it isn’t working now that would cause you to duplicate the page header code in the After Header hook? Just trying to figure out how all the pieces fit together.
Tom – if I’m missing something here or you have some other thoughts, feel free to jump in. Thanks.
October 1, 2015 at 9:25 pm #141332DavidI’ll post the inquiry this way. Where should I place this code?
<?php if (is_page_child(201) ) : ?> <div class="page-header-content generate-page-header generate-content-header"><div class="inside-page-header-container inside-content-header grid-container grid-parent "> <header style="display:block;" class="entry-header"> <h1 class="titlebar"><?php the_title(); ?></h1> </header></div></div> <?php endif; ?>
October 1, 2015 at 10:53 pm #141338TomLead DeveloperLead DeveloperGenerally, you would place that in the “After Header” hook, which it looks like you’re already doing.
I see the duplication on some of the pages on your site – where is that second area coming from (assuming one of the areas is the function you added above)?
-
AuthorPosts
- You must be logged in to reply to this topic.