Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress WordPress Theme Development Adding a Blog to a WordPress Theme Coding the Blog Homepage

John Ewell
John Ewell
1,730 Points

Blog post titles not displaying

I am following the video, setting up my home.php file. Sri far everything works, EXCEPT that post titles are not showing up. The code that should display the titles looks like this:

      <article class="post">
            <h1><a href="<?php the_permalink(); ?>"<?php the_title(); ?></a></h1>
        <h2><?php echo strip_tags( get_the_excerpt() ); ?></h2>

On the blog page the excerpt displays with no problem, but the line above it is blank.

When I inspect the generated source code, the h1 tag that should display the title looks like this:

        <h1>
            <a href="http://localhost/localwp.com/2016/11/26/hello-universe/" hello="" universe!<="" a=""></a>
        </h1>                

But it is immediately followed by another version of the title link, which is not embedded in an h1 tag and includes the whole h2 excerpt:

        <a href="http://localhost/localwp.com/2016/11/26/hello-universe/" hello="" universe!<="" a="">
            <h2>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada […]</h2>
        </a>

Is there a bug, or am I doing something wrong?

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

I suspect the answer is you need to close the opening part of the hyperlink. PHP is just getting confused about the structure of your link tag. :-)

<article class="post">
            <h1>
               <a href=" <?php the_permalink(); ?> "> 
               <?php the_title(); ?></a></h1>
              <h2><?php echo strip_tags( get_the_excerpt() ); ?></h2>

Try putting in a ">" just after your second quotation mark that is the href attribute of your link tag.

John Ewell
John Ewell
1,730 Points

Thanks Jonathan! That was exactly what the problem was. Once I added the angle bracket to close the opening part of the hyperlink tag the titles all magically appeared.

I'm using Linux-based emacs on a mac, which doesn't color code for syntax. Perhaps I should switch editors...