Blog

Sharing WordPress tips and tricks as I find them

Automatically display titles on Category and Tag Archives

The archive pages in Genesis can be a bit confusing. Other than the URL (and breadcrumbs if you have them turned on), they look exactly the same as the main blog.

Genesis provides a useful feature for adding headlines and intro text to the top of your archive pages. Go to Posts > Categories and edit a category to see the screenshot above. But this requires you to manually type it in for each category. If you have a lot of categories this can be a hassle.

Add this code to your theme’s functions.php to automatically default that field to your category name. If you provide an “Archive Headline” when editing a category, that is used. But if you don’t, the category name is used.

This applies to categories, tags, and any custom taxonomies you’ve created.

17 Comments

  1. Thanks for the quick tip bill. This is helpful and timely.

  2. Bill,
    I’ll second Craig’s comment, a very nice bit of code, so many of which you offer here.

    This comes up as a forum question sometimes, and now there’s a place to send them. :)

    Thanks,
    Dave

  3. Excellent Bill, I’m definitely using that. Thank you for sharing.

  4. I’m always so impressed by the elegance of your solutions! I’ve added titles to archives several times in the past by putting code to retrieve and output the term into the appropriate template file, completely overlooking the built-in headline functionality. I’ll definitely be adding this into my base child theme for future use. Thanks Bill Erickson!

  5. Victor Marsala says:

    I have a general question in terms of your approach to client edits.

    I have more and more clients that want to handle creating their own content and maintaining it, and while the days of pasted-in Microsoft Word headaches are nearly over, it seems counterintuitive to think just how few people know anything about HTML or how it works, or listen when provided with a few pieces of information relevant to get the job done.

    If someone wants a video gallery, rather than make them copy and paste divs and headers and URLs, I’ve sometimes just done it WerkPress style and made a custom post type for videos and told them each video “post” is aggregated on the gallery page. And that’s fine.

    But recently I keep having things like someone who wants a simple schedule, where you click the times and it reveals in a jQuery slideToggle what takes place at that time. I say just copy and paste the two lines, and edit the text of it for the bold and non-bold bits, and the script will do the rest.

    It seems like overkill to make an entire post for two lines of text, so I don’t want to do that to them, but if they edit the text in the Visual tab, WordPress can mess with the formatting, and if they copy and paste in the Text tab, I’ve seen three different ways the formatting can be broken at the same time on the same page. Even something as simple as getting the nesting wrong can be disastrous.

    The themes run great (thanks, Genesis) and the actual custom coding and scripting are effective at what they do. But without some protected way of editing specific areas (almost like Publisher, or vaguely like Photoshop layers) I don’t know how to save them from themselves. Do you just make redundant code that tries to sniff out every possible break? It seems awkward and limited.

    • Bill Erickson says:

      I make extensive use of custom metaboxes. My goal is for clients to never see (or need to know) HTML. So if there’s anything that can’t be done easily through the visual editor, I’ll build a metabox for the client to manage it.

      For instance, here’s a page on a client site, and here’s what the backend looks like to manage it: http://cl.ly/image/2s3o22373Q3h.

      • Victor Marsala says:

        Wow, that’s an interesting take! A lot going on, but highly organized. My first thought was “How does it fit for a schedule scenario,” but the whole idea of a schedule is that everything’s fixed, and the only things they should be editing anyway are time ranges and descriptions, not how many entries there are.

        Thanks for the feedback. You’re always so professional and generous with what you share and I hope nothing but continued success for you. Thanks for your positive contributions to both WP and Genesis and their respective communities!

  6. Bill,

    Thanks for writing this up.

    Here’s the possibly-slap-my-forehead question for you.

    Why does Genesis include the extra “Archive Headline” and “Archive Intro Text” on category & tag pages when WordPress already supplies the “Name” and “Description” fields? For our Genesis theme, long ago I added code to the functions file to simply write the WordPress “Name” and “Description” on category & tag pages, due to this confusion you speak of.

    Thank you.

    • Bill Erickson says:

      I’m not sure why Genesis creates its own fields. My guess is so that you could have a title that’s different than the category name. So the category might be “News” and your archive title is “News about Company XYZ”. Alternatively, you might add descriptions to your categories to be used in the backend or in mega menus, but not want them displayed at the top of the archive pages.

      I think the simplest answer is that by providing additional fields, Genesis doesn’t have to assume how you want things structured. I prefer the “Decisions, not Options” approach personally.

  7. Thank you very much for sharing this. How should I modify the code to be able to show also the archive intro text for each category automatically?

  8. Thanks Bill, you’re amazing. Sorry if I ask it here: have you already made one of your beatifully neat snippets for managing sidebars and menus? I’ve been using the plugins “Simple Sidebars” and “Simple Menus”, but they seems to be able to modify only the pages created by the user, while I need to dynamically change also the sidebars and menus displayed in 404, archives and not found pages.

    • Bill Erickson says:

      I typically build it manually in the theme. Ex: https://gist.github.com/billerickson/535f042d569c2683f6cc

      • I see, so the only way is to do it manually… I’ve added your code and it works like a charm, but my sidebar is now empty obviously. Could you please tell me also how to add widgets to it? I hope I’m not bothering you too much with my questions.

        • Bill Erickson says:

          That code creates a sidebar called “Archive Sidebar”, so go to Appearance > Widgets and add widgets to the Archive Sidebar.

          • I just realized why I couldn’t see the sidebar in Appearance; I had to add a piace of code to the register_sidebar including the name of my theme. Which is the Is_function() for applying it also to search pages with results and not found search pages? Again, thank you for everything, I’m very satisfied.

  9. I found out how to do it. You can remove this and the previous message, thanks. :)

Join the Conversation

If you'd like to include code in your post, please post it to http://gist.github.com and include a link.