[Resolved] Page Header for Unique Child Pages

Home Forums Support [Resolved] Page Header for Unique Child Pages

Home Forums Support Page Header for Unique Child Pages

Viewing 15 posts - 1 through 15 (of 26 total)
  • Author
    Posts
  • #141007
    David

    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!

    #141015
    Tom
    Lead Developer
    Lead Developer

    Hi David,

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

    #141018
    bdbrown

    The first answer on this StackOverflow post might help.

    #141022
    David

    @Tom. That is correct.

    Thanks!

    #141097
    Tom
    Lead Developer
    Lead Developer

    bdbrown linked to a post with the answer above: https://generatepress.com/forums/topic/page-header-for-unique-child-pages/#post-141018

    That should work πŸ™‚

    #141108
    David

    Thanks I will put that in action.


    @bdbrown
    Thanks again!

    #141193
    bdbrown

    You’re welcome πŸ™‚

    #141194
    David

    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!

    #141200
    David
    #141237
    Tom
    Lead Developer
    Lead Developer

    Awesome, thanks for posting the code! πŸ™‚

    #141243
    bdbrown

    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.

    #141279
    David

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

    #141321
    bdbrown

    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.

    #141332
    David

    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; ?>
    #141338
    Tom
    Lead Developer
    Lead Developer

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

Viewing 15 posts - 1 through 15 (of 26 total)
  • You must be logged in to reply to this topic.