• FYI, my theme is based on _s.

    My home page is using front-page.php and I’m pulling in ‘name’ and ‘description with bloginfo and using header-front-page.hp for that page.

    I used add_post_type_support( ‘page’, ‘excerpt’ ); to add an excerpt field for the pages so that I could put that field and the page title in the header using:

    <?php
    while(have_posts()) {
    the_post(); ?>
    <h1 class=”page-title”><?php the_title(); ?></h1>
    <h3 class=”page-description”><?php the_excerpt(); ?></h3>
    <?php }
    ?>

    I didn’t know it would wrap the excerpt in a <p> tag so the styling was a little messed up but that was an easy fix.

    But I create a blank page called Blog for my main blog page and I added a brief excerpt for it as well, but that created problems.

    1. It put the title and the excerpt for each post on the blog page in the header. It didn’t even include the Blog page title or excerpt for that page.
    2. I created a header file called header-posts.php and just put in:

    <h1 class=”page-title”><?php the_title(); ?></h1>
    <h3 class=”page-description”><?php the_excerpt(); ?></h3>

    But what that did was put the title and excerpt in the header for the first blog post on the page. Ahhhh!

    I’m a newbie at this so I assume there is a simple fix that I am missing, and you may not even think the way added the page excerpt is the best. Oh, and all my archive pages are messed up now unless I add get_header( ‘post’);.

    Any idea how to get the title and excerpt for my “Blog” page into the header?

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m not clear from your post what you are trying to achieve.

    > Any idea how to get the title and excerpt for my “Blog” page into the header?

    You want the title and the excerpt to display on the Blog *index* page ?
    Or individual blog post page ?

    Thread Starter Jim

    (@kernix)

    I added the excerpt field for pages. I wanted each page to have a title and “tagline” to be unique. So I figured using the excerpt field for pages is like the tagline for the home page. It worked – except for the PAGE called Blog. I do not want the title and excerpt for individual posts to appear in the header for individual posts, just the excerpt for the Blog page to show up in the header as it did for the other pages.

    I’m fine with the site title and tagline for individual posts. Do you understand? When I first learned WP I never knew you were supposed to create a blank page called Blog or Articles which would be your main blog page. Usually, that would default to index.php but I created home.php for that page.

    But putting the excerpt in the header for my main blog page, which I named Articles, is pulling in either the excerpts for all 10 posts on each page – OR – the excerpt for the first post on that page. Even though, the page I created for my blog roll has an excerpt field.

    As a newbie maybe I’m doing things that more experienced people would do in a “better” way, but I now have custom headers for all my pages – except the “blog” page.

    Moderator bcworkz

    (@bcworkz)

    Hi kernix — I read through this topic quickly, I hope I comprehended it correctly. I think the gist is on your blog listing page you want the header content different than on any other pages. Since you already have a custom template for this page (home.php), you could also have an alternative header template to go with it. On home.php, there’s presumably a call to get_header(), which loads the default header file, header.php. You can pass a value to that function to have it load a different file, header-home.php perhaps. In which case you’d do get_header('home');

    Alternately, place a conditional statement in header.php to do one thing for most pages, but do something else for the blog page. is_home() returns true for the blog page, even if it’s not your site’s static front page. So you could set up something like:

    if ( is_home() ) {
      // do or don't do something for the blog listing page
    } else {
      // do something else for other pages
    }

    is_home() returns false for static front pages, even though such a page is often thought of as “home”.

    Thread Starter Jim

    (@kernix)

    Yes, I want different header content for each page. For front-page the title and tagline are fine. For every other page, I did get the title of the page and the excerpt I created for each page – 5 or so keywords. But that does not for the blog page. So I guess it’s something to do with home.php and the fact it has the blog roll and all the other pages are using page.php.

    I’m a newbie so I’m overlooking something, But it’s not the end of the world if I can’t easily do it. The blog page and all archive pages are the only pages with a sidebar – so if the header is the same for all of them then that’s okay.

    Here is my site where you can see the different page name and description in the header: I just finished the last page – still a lot of design changes to do: https://kernixwebdesign.com/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Help with pulling in the_title and the_excerpt into header.php’ is closed to new replies.