WordPress Archive Pages: the tutorial

WordPress archive pagesOn any bigger site, you’ll get archive pages of some sort. Whether they are taxonomy or category archives, like this SEO category, Custom Post Type archives like this one for our WordPress plugin reviews or my speaking engagements, or even date archives: they all share the same common traits. In WordPress an archive will, by default, consist only of a listing of posts. As these pages will get visited by normal people, that means those visitors are “thrown” upon a page that doesn’t try to tell them where they are.

This lack of introduction gives visitors only two options: leave immediately because they don’t understand where they’ve ended up, or click through to an article, without you having had any chance of pushing them in the right direction.

Because of that, every decent archive needs an “introduction”. This can be as simple as just a header that stands out, but for more important sections of your site, it actually pays of to write a bit of content.

Before you write that content though, you first have to make sure that the content you write actually displays on those archive pages.

Show introductory content on archive pages

Categories, Tags and Custom Taxonomies

For category, tag or custom taxonomy archives, you can simply create a custom template by creating a file. For categories, for instance, this file would be called category.php. If you don’t know how template hierarchy works within WordPress, check out our infographic on the topic.

In this template, above the standard WordPress loop, you add the following code:

if ( !get_query_var( 'paged' ) ) {
  echo wpautop( term_description() );
}

If you want shortcodes to work, try this:

if ( !get_query_var( 'paged' ) ) {
  echo wpautop( apply_filters( 'the_content', term_description() ) );
}

This uses the title you set for the category / tag / custom taxonomy, as well as the description, which you can fill in the WordPress backend. If you uses Genesis, you don’t need to create an extra file, you can probably just check the box in your Genesis theme settings: Genesis Archive Settings Or if that doesn’t work, you can just add this to your child theme’s functions.php (there’s still no need to make that file):

function yoast_term_archive_intro() {
  if ( !is_category() && !is_tag() && !is_tax() )
    return;

  if( get_query_var( 'paged' ) )
    return;

  echo '</pre>
<h1 class="entry-title">'.single_term_title('', false).'</h1>
<pre>
';
  echo '</pre>
<div class="entry-content">'.wpautop( term_description() ).'</div>
<pre>
';
}
add_action( 'genesis_before_loop', 'yoast_term_archive_intro', 20 );

Of course you can add some extra code or classes in there to style those boxes a bit more.

Custom Post Type archives

For custom post type archives, this might actually be a bit harder. The beginning of the process is the same: you can create a new file, the name of which should contain your post type: archive-{posttype}.php. Then you could output the name of the post type using the following code:

if ( !get_query_var( 'paged' ) ) {
  $pt = get_post_type_object( get_post_type() );
  echo '</pre>
<h1>'.$pt->labels->name.'</h1>
<pre>
';
}

This is where the tricky bit comes in though: there is no backend in WordPress to input descriptions for these types of pages, nor is there a preferred way of storing that data. I added input fields for these to my Genesis child theme settings, which is too much to explain here, of course you could also hardcode it but that’s a bit ugly… Within Genesis, with the data coming from my child theme settings, I output the text using the following code in my functions.php (again, no reason to create a new file):

function yoast_cpt_intro() {
  if ( !is_post_type_archive() )
    return;

  if( get_query_var( 'paged' ) )
    return;

  $pt = get_post_type();
  if ( genesis_get_option( $pt.'-title', 'child-settings' ) ) {
    echo '</pre>
<h1>'.genesis_get_option( $pt.'-title', 'child-settings' ).'</h1>
<pre>
';
    echo wpautop( genesis_get_option( $pt.'-intro', 'child-settings' ) );
  }
}
add_action( 'genesis_before_loop', 'yoast_cpt_intro', 20 );

Prevent duplicate content

To avoid duplicate content, we only add the introduction to the first page of an archive, if that archive is a paginated one. With the introduction of rel=”next” and rel=”previous”, sites that have implemented this well will be getting more visitors to the first page of a paginated series of archives anyway, but we still don’t want to show the same content on multiple pages.

You might have noticed this line of code in the Genesis examples above:

if( get_query_var( 'paged' ) )
  return;

This does exactly that: prevent the duplicate content.

Styling the archive introduction text

You should make sure that your introductory text for your archive really stands out. Remember, it’s not “just” there for SEO reasons, it’s there because people will read it! It’s very tempting to make it look just like another post, but you should take a bit more time and style it properly.

I personally like the way we’ve done that in our recent redesign, this is for instance what the WordPress category intro looks like:

WordPress category introduction

Of course, the text for that introduction is a bit poor. I should probably do a much better job myself of explaining people where to go for what kinds of content, so I’ll get right on that once I finish this post… Which brings me to the last bit:

HTML in category descriptions

HTML in descriptions for categories, tags and custom taxonomies is currently disallow by default. I think that’s changing in an upcoming release, but for now you’ll have to fix that. If you’re using my WordPress SEO plugin, this has already been fixed for you, if not, AppThemes has quite a good tutorial on it.

Let me know what you did with your archive pages in the comments, I’m very curious to see good examples!

Tags: ,


Yoast.com runs on the Genesis Framework

Genesis theme frameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides you with the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Read our Genesis review or get Genesis now!

34 Responses

  1. JulienBy Julien on 22 August, 2012

    An example of my archive page : http://www.jguiss.com/referencement/

    I add the category description and i left only title, small thumbnail and comment number of posts.

    Bye

  2. GaryJ, Gamajo TechBy GaryJ, Gamajo Tech on 22 August, 2012

    No need to add code for Genesis Custom Post Type Archives – there’s a plugin for that! http://wordpress.org/extend/plugins/genesis-custom-post-types-archives/

  3. RajeshBy Rajesh on 22 August, 2012

    Joost, please tell me meaning of parameter: ’20′ in this line

     add_action( 'genesis_before_loop', 'yoast_cpt_intro', 20 );  

    Sometimes there is value ’10′ what does it mean.

    Also I didn’t get logic behind this:

     if ( !is_category() && !is_tag() && !is_tax() ) 

    To show something on tags, category we generally use

     ( is_category() || is_tag() || is_tax() )  

    I’ve code provided by you it’s working but I didn’t get the logic behind it.

    • Joost de ValkBy Joost de Valk on 22 August, 2012

      - The “20″ is so it loads after the breadcrumbs
      - the second bit is to return early instead of do an if statement around the whole code, just easier to read that way.

      • RajeshBy Rajesh on 22 August, 2012

        Okay got it, if there is a page other than category, tag or taxonomy and on paged it’ll return nothing and on remaining pages means on category, tag or taxonomy pages it’ll show the description with h1 tag. Nice logic. Thanks for the article.

  4. AndersBy Anders on 22 August, 2012

    Here is mine: http://www.wpsecuritychecklist.com/category/wordpress-security-plugins/

    On this particular category it is crucial with the intro text to lead people in the right direction.

    Thanks a bunch for this article!!

  5. MarkBy Mark on 22 August, 2012

    Regarding HTML in taxonomy term descriptions, I’ve had good luck with the Rich Text Tags plugin (http://wordpress.org/extend/plugins/rich-text-tags/) which adds the WYSIWYG editor to every taxonomy term’s description field.

  6. seriocomicBy seriocomic on 23 August, 2012

    Slightly OT, but what remarkable timing.
    I was reading through WordPress support forums last night trying to figure out how to turn off pagination (rel=) on my very old photoblog theme (something that your awesome SEO plugin reintroduces).
    Turns out there are plugins that allow you to set the posts-per-page value to -1 to set the ‘paged’ value to false.
    Not all themes are broken, not everyone uses frameworks…

  7. Pat FortinoBy Pat Fortino on 23 August, 2012

    Thanks for this helpful tip. I think there might be some code missing in your first code example:

    if ( !get_query_var( 'paged' ) ) {
      <h1><?php single_term_title(); ?></h1>
      <?php echo wpautop( term_description() ); ?>
    }

    Should be:

    <?php if ( !get_query_var( 'paged' ) ) { ?>
      <h1><?php single_term_title(); ?></h1>
      <?php echo wpautop( term_description() ); ?>
    } ?>
  8. ChrisBy Chris on 23 August, 2012

    Hey Joost,
    Thanks for the tut!
    I noticed in google search result when you type “yoast” underneath your meta description there is nav bar with links “Top Links” “WordPress Plugin” “SEO” etc.
    Are we able to add a nav bar underneath the meta description with your wordpress seo plugin?

  9. DHgateBy DHgate on 23 August, 2012

    Thanks a lot for the tutorial. Now I’m acknowledged more to run my own blog.

  10. GerardBy Gerard on 23 August, 2012

    Hi Joost!

    I use something similar since one year ago. In my category.php file I put that code:
    <?php if ( $paged

    cat_name ?>

    So, if I am in the page < 2, print the category_description.

    Today I'm also making a code for SILO structure: If is category and page 1, the H1 has the single_cat_title and the end ” | Page n (number)”.

    Then, I also added a function in functions.php because I don’t want that a post posted in a child category is showed into the loop of the parent category. It is a great structure for SEO, I think. Like static website but with dinamic content. This structure reverses the hierarchy. WordPress shows all the recent content in the beginning, and now my theme shows all the recent content in the appropriate beginning, but not at the top of all archives. For example, category Animals, subcategory Dogs, and subcategory Dalmata; the post of the Dalmatas will be in the subcategory Dalmata, in the home page and into the feed, but the structure of the category will be static-like (if we no index the tag, author and archive, lol). You can find this function here: http://scratch99.com/wordpress/wp-seo/siloing-links/
    It is useful if you use subcategories. And it would be good to use the permalink /animals/dogs/dalmata/dalmata-post/, but is late for me.

    Anyway, you can create a new category template by adding the ID in the file, and then you can optimize the page with html.

    Sorry for my English.

  11. MariusBy Marius on 23 August, 2012

    So, does this works only with Genesis or with other themes as well?

  12. palPalaniBy palPalani on 23 August, 2012

    Good article.
    Breadcrumbs not showing the paging [ Page 2 of 3 ] details. is it not needed?

  13. ScottBy Scott on 23 August, 2012

    I used the plugin “Category Redirect to Post or Page” to emit a page with information which is relevant to each category. That information then is followed by the archived blog posts — I’m using the Weaver theme, which offers a “page with posts” template, and a way to specify what category’s posts should be on each page. Pagination is offered for browsing the category posts, with the intro text only being offered on the first page of the archive.

  14. GerardBy Gerard on 23 August, 2012

    I wonder what I can do if I use the excerpt as metadescription. Less than 160 characters. Any suggestions?

  15. ShashaBy Shasha on 24 August, 2012

    Great Article..Joost..
    I think all articles are coming in favor of genesis…

  16. Brad DaltonBy Brad Dalton on 24 August, 2012

    Chris Pearson from DIY themes (Thesis) wrote about this last year http://www.pearsonified.com/2011/06/wordpress-category-page-seo.php

    Why don’t you use featured images in your archives? Google image search would send you more traffic if you did.
    Not all Genesis child themes include the feature to activate the intro text in archives and the framework itself doesn’t.
    You’ll need to add the code from this post but make sure you remove the opening php tag or you will get a server error. i.e <?php

    P.S Good to see you have fixed the problems with your plugin.

    Here's what my tag archives look like which are no index.

    You can add video's, html or anything in the introductory area on all your archives

    http://wpsites.net/tag/wordpress-managed-servers/

    • Joost de ValkBy Joost de Valk on 24 August, 2012

      I’m not really interested THAT much in generic image search traffic. Haven’t seen it convert well here yet.

  17. Daniel RochBy Daniel Roch on 24 August, 2012

    Nice post about archives pages.

    But people have to be carefull about date and author archive. For many websites, they are useless (only one author or noe date related content). In those case, it’s better to remove them in order to improve contents for users and SEO .

  18. Jarl KubatBy Jarl Kubat on 24 August, 2012

    Thank-you Yoast, for your help in making my WordPress blog more profitable,

  19. JANGAN DIKLIKBy JANGAN DIKLIK on 25 August, 2012

    This works only with Genesis or other themes as well? :roll:

  20. escendolBy escendol on 26 August, 2012

    this my blog not work
    On this particular category it is crucial with the intro text to lead people in the right direction.

  21. DawidBy Dawid on 27 August, 2012

    Thanks for the tutorial.
    Good article.

  22. Cycle SamuelBy Cycle Samuel on 28 August, 2012

    Yoast,

    I have been doing this for a while now with varying degrees of success. I have always found it hard to rank category pages in Google even with large amounts of custom content at the top of the page. However from a UX perspective it is perfect for reducing traffic leakage.

    Quick question: When I add custom content to the description field of the wordpress category, the sitemap does not update the last updated date. Should this happen automatically or do I need a piece of code with my archives template??

    Would appreciate your thoughts on this.

  23. casperlee290By casperlee290 on 28 August, 2012

    Yes Introduction is the most important part of any site because when visitors came to your site and want to go through with all about what your site is, they can just read your introduction part other wise they may leave and go for next.

  24. chrisBy chris on 31 August, 2012

    I can’t find a way to email you about your wordpress SEO article (no commenting) so I’m posting here…On point #8, Measuring Results, you list a method of using google webmaster tools to find the site pages that rank lower than 6th. I tried this and those with the most clicks were pages that were listed in the top 3 on the front page.

    My question then is how can I have a site page that’s ranked #1 on Google but the Google Webmaster Tool says it ranks #6?

  25. SidBy Sid on 1 September, 2012

    How come you are not using your plugin in your new site?

  26. Zoe ThacherBy Zoe Thacher on 1 September, 2012

    Thanks for the tutorial. Very interesting and get more ideas from your blog.

  27. Phil MooreBy Phil Moore on 1 September, 2012

    This is a really nice tutorial – something I had been wondering about for a while. Off to set this into action on my blogs now. Thanks!

  28. LionelBy Lionel on 1 September, 2012

    Thanks for writing this brief instruction about archive pages, now i have to do some works on my site.

  29. Patrick NommensenBy Patrick Nommensen on 3 September, 2012

    Thanks for the tutorial Joost :-). In case anyone was wondering, this functionality is very easy to include with the Catalyst Framework using a hook with the Dynamik child theme. Looking forward to your future posts!

  30. ThomasBy Thomas on 7 September, 2012

    Glad my site is not so big. Its easier for me to just redirect them?

    You think that’s a good idea or is it better to have outdated material that takes up crawl time?

  31. BUDE SEOBy BUDE SEO on 9 September, 2012

    Thankyou tuttorial yoast ;D
    good information