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 trialLydia Roberts
3,535 PointsWordPress Archive page title not printing
Using Zac's Bootstrap to WordPress course, I've created a very custom theme and fleshed it out a good deal.
I run into trouble with the Archive (archive.php) template and the Search Results page (search.php). Neither one prints the title of the page correctly.
The archive page prints nothing - totally blank. I'd like it to print the name of the category/tag/date.
The searchform page prints the title of the first page/post. I'd like it to print "Search results for: [name of search term]"
What is the correct code needed to print the page titles? I've tried lifting bits of code from base templates like twentyfifteen but not getting any correct results. I'm kind of a php beginner. Thanks!
1 Answer
Jason Campbell
9,822 PointsHi Lydia, I haven't taken that course yet but I have developed in WP quite a bit. The function the_title() may work for that. Or you can search around the WP codex if that doesn't work.
http://codex.wordpress.org/Function_Reference/the_title
Hope that helps. -Jason
Lydia Roberts
3,535 PointsLydia Roberts
3,535 PointsThanks for your reply, Jason. That function doesn't quite cover these scenarios but I was able to search around and cobble together the following which works well for archive.php:
I hope that might help others. Basically the above will print out different things based on if it's an archive by day, month, year, category, or tag.
I haven't figured out the right format for the Search page yet.