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

sean z
sean z
667 Points

why close the div at the start of header.php?

I have a huge problem with this step at 1:14 of the video here: http://teamtreehouse.com/library/how-to-build-a-wordpress-theme/extending-wordpress-template-functionality/finishing-the-homepage-template-2

I'm not going to close a div that was opened in another php file. It's just bad practice in my mind when it can be avoided and it can be avoided in this case as far as I can tell.

<div class="container clearfix">

That container needs to contain each of the grid classed divs in the grid system used for this demonstration. It was started/opened in the header.php for the header section and it should also be closed in header.php. Most CSS grid systems that I've seen almost always have the concept of a row container (for multiple columns or cells) and that's what I'm seeing this as.

Of course doing that throws the rest of the home page out of whack... so you also need to add that container div to contain the html that was put into footer.php and content-testimonials.php. You'll need to find all other instances where the container wasn't added before grid classed div(s) to fix any other pages too.

Once I fixed these my way, I don't run into the issue the video shows at 7:18 where he seemingly randomly picks a closing div to remove from front-page.php.

Maybe this is just my opinion or perhaps a misunderstanding of the CSS grid system for this demo but it really bothered me that the header.php didn't close the container div in the earlier video when it was instructed to put the html into header.php and I felt kind of validated when this video instructed me to close the container from header.php in front-page.php.

1 Answer

This is a WordPress quirk, but some minutes of googling around doesn't bring illumination as to why they do this. In fact, the Codex says: "If you start a HTML tag or div in one template file and don't close it there, make sure you include the closing tag in another template file. "

Which certainly strongly implies that you can do it either way, which of course circles one back around to the original question: WHY would you close a tag in a different file - that seems confusing and potentially bug-prone. So I don't have a good answer for you, but it's an interesting question and it'd be great if anyone with any insight would pop in and share. :)