Site logo

Archived topic

Page Header for Unique Child Pages

25 replies · Started by David on September 30, 2015

Viewing posts 1–15 of 26

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!

Hi David,

So you want that block to show up only on child pages of your 201 parent ID?

@Tom. That is correct.

Thanks!

Thanks I will put that in action.

@bdbrown Thanks again!

You're welcome :)

This 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!

Awesome, thanks for posting the code! :)

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

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

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

I'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; ?>

Generally, 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)?

This archived topic is closed to new replies.