Help with pulling in the_title and the_excerpt into header.php
-
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?
- The topic ‘Help with pulling in the_title and the_excerpt into header.php’ is closed to new replies.