How to Create a Blog Series.. Technically Speaking

How to create a blog series (technically speaking)

I recently started (but sadly, haven’t finished) a blog series called How to Start a Blog. When I did this, I wanted a new archive system that would display the posts in these series in a slightly different way than normal.

Tags show posts in descending order

First I created a tag called How to Start a Blog. But I didn’t like that archive view because it showed the posts in reverse order, with the newest at the top and the oldest at the bottom.

That’s not ideal because when people are starting out, they should be starting at the beginning!

A new taxonomy for series

So I created a new custom taxonomy that works just like categories or tags, but instead it shows posts in the opposite order: with the oldest at the top and the newest at the bottom.

Code for a new taxonomy

You can use the Generate WP Taxonomy Generator to create your custom taxonomy code. You can leave most of the options at the defaults, but here are the important ones:

  • Taxonomy Key: Set this to something relevant. I chose blog_series
  • Name (Singular) Choose a name for your taxonomy, such as Blog Series or just Series will do too.
  • Name (Plural) Same as above, but the plural form of the name.
  • Hierarchical: This is totally up to you. It’s basically whether or not you want the box to look like categories (with a list of all series with checkboxes) or tags (where you type it in yourself).
  • Labels: Adjust all the labels to match your taxonomy name.

Here’s what my final code looks like:

// Register Custom Taxonomy
function blog_series_taxonomy() {

	$labels = array(
		'name'                       => _x( 'Blog Series', 'Taxonomy General Name', 'nosegraze' ),
		'singular_name'              => _x( 'Blog Series', 'Taxonomy Singular Name', 'nosegraze' ),
		'menu_name'                  => __( 'Blog Series', 'nosegraze' ),
		'all_items'                  => __( 'All Series', 'nosegraze' ),
		'parent_item'                => __( 'Parent Series', 'nosegraze' ),
		'parent_item_colon'          => __( 'Parent Series:', 'nosegraze' ),
		'new_item_name'              => __( 'New Series Name', 'nosegraze' ),
		'add_new_item'               => __( 'Add New Series', 'nosegraze' ),
		'edit_item'                  => __( 'Edit Series', 'nosegraze' ),
		'update_item'                => __( 'Update Series', 'nosegraze' ),
		'view_item'                  => __( 'View Series', 'nosegraze' ),
		'separate_items_with_commas' => __( 'Separate series with commas', 'nosegraze' ),
		'add_or_remove_items'        => __( 'Add or remove series', 'nosegraze' ),
		'choose_from_most_used'      => __( 'Choose from the most used', 'nosegraze' ),
		'popular_items'              => __( 'Popular Series', 'nosegraze' ),
		'search_items'               => __( 'Search Series', 'nosegraze' ),
		'not_found'                  => __( 'Not Found', 'nosegraze' ),
	);
	$rewrite = array(
		'slug'                       => 'series',
		'with_front'                 => true,
		'hierarchical'               => true,
	);
	$args = array(
		'labels'                     => $labels,
		'hierarchical'               => true,
		'public'                     => true,
		'show_ui'                    => true,
		'show_admin_column'          => true,
		'show_in_nav_menus'          => false,
		'show_tagcloud'              => false,
		'rewrite'                    => $rewrite,
	);
	register_taxonomy( 'blog_series', array( 'post' ), $args );

}

// Hook into the 'init' action
add_action( 'init', 'blog_series_taxonomy', 0 );

Then, refresh your permalinks

A blog series taxonomy box in WordPress

After you’ve added the code to your site, you’ll have a brand new section for “Blog Series” in your sidebar when adding/editing a post!

But if you add some posts to this taxonomy and view the taxonomy archive, you’ll get a 404 error. This is because you have to refresh your permalinks. Just go to Settings » Permalinks and click Save. You don’t have to make any new changes—just save.

Now all that’s well and good, but all we’ve done so far is add a new taxonomy box. If you view the archive, posts still show in descending order!

To fix that, we need another piece of code.

Change the order of posts for your taxonomy

What we need to do is edit the query ONLY for this taxonomy archive page.

/**
 * Changes the order that posts get displayed in
 * when we're querying a blog series or book series.
 * 
 * @param $query
 * 
 * @return void
 */
function change_blog_series_post_order( $query ) {
	if ( $query->is_main_query() && is_tax( 'blog_series' ) ) {
		// Reverse the order the posts are displayed in.
		$query->set( 'order', 'ASC' );
	}
}
add_action( 'pre_get_posts', 'change_blog_series_post_order' );

What we’re doing is saying:

  • If we’re in the main WordPress query
  • AND we’re looking at the blog_series (this should be your taxonomy key) taxonomy
  • THEN set the display order to ascending

Useful for other taxonomies too!

This is a super useful snippet that can be useful for other taxonomies too. In fact, I’ve done the same thing for my book series taxonomy. Here’s an example: Series: The Selection. You can see that the books are shown in ascending order, with the first book in the series at the top.

Download the plugin

I’ve packaged up a plugin with the exact code snippets shown here. If you want, you can download the zip file and install it like any other plugin. Make sure you re-save your permalinks after activating it!

Photo of Ashley
I'm a 30-something California girl living in England (I fell in love with a Brit!). My three great passions are: books, coding, and fitness. more »

Don't miss my next post!

Sign up to get my blog posts sent directly to your inbox (plus exclusive store discounts!).

You might like these

22 comments

  1. As usual, you are always sharing awesome things with us. I have one question though. Is it possible for me to now to add my blog series between the category and the post slug in the post URL? example… right now my site has site-name/category/post-slug but cannot access the link thru site-name/category/blog-series/post-slug.

    Kayla @ The Review Court recently posted: Book Trial: Unelmoija: The Dreamshifter
      1. after I sat and thought about it, i think I will just change the permalinks to show site-name/post-slug…. that way when I change categories and do things like this I don’t have to run into this issue. Thanks a million though. I was reading some of the same posts you sent and then while trying to fix my permalinks, realised all my links were messed up.

        1. I think that’s best. 🙂 And site-name/post-slug is super clean! And short! Short URLs are awesome.

  2. Ashley! Do you know how perfect this is? I’ve been planning to do a series where I explain some of the things that I do and why I think it’s beneficial, and this is just so perfect. I’ll take this as a sign to go through with the idea. 😀 Thanks for all the awesome stuff, Ashley!

    Shannelle recently posted: The Summer Story of May 16, 2015
    1. I’m so glad this is useful to you! 😀 What awesome timing. Good luck with your series!

  3. I followed your steps but I was confused as to where to paste the copied snippet. I’m a total idiot though with coding so I searched available plugins and found a free Series plugin that does this. It’s called, Series. I just downloaded it and it works!

    But, if I hadn’t stumbled across this tutorial on Pinterest I’d still be wondering how to do it. Thanks so much for taking the time to post this tutorial!

Recent Posts

    Random Posts