How do I Customize the Latest Series?

One of the things that the  Organize Series WordPress plugin does well is provide multiple ways for you to promote and "show off" the various series you've written. Since some of those possibilities aren't easily visible to the new user this next few posts in the series will give you a list of all the different ways you can publicize your serial work.

Latest Series - <?php latest_series(); ?>

This function is one of the few features of Organize Series that is not automatically enabled right out of the box on fresh Organize Series installs. However, it is a powerful way for you to promote the latest series you've published (or are in the midst of writing).

How to use it:

To use the latest_series() function you need to be familiar with editing your theme files. There are some great pointers for this  herehere, and here. The latest_series() function can be placed wherever you want - inside or outside of the WordPress loop. What will happen is that when the page is generated the function instructs WordPress to display the latest series using the layout defined in the by what you have included in the Latest Series Template in the Series Options Page. So you can control the output via the series options. By default, the latest_series function will display the series icon for each series listed.

So let's take a look at actually using this tag. Let's say you want to insert the latest series information in your sidebar and you want it to display the series icon, a description of the series, and let's throw in a list of the posts in that series as well. First, we need to set up the "Latest Series Template" via the series options page. It will look like this:

\

Notice that I've used the following %tokens%:

  • %series_icon_linked% - which gets replaced with the series icon for the latest series (if there is one)
  • %series_description% - which gets replaced with the series description for the latest series (if there is one)
  • %post_title_list% - which gets replaced with the list of posts in the series (according to the " Series Post List Template" on the Series options page. I've also styled it using html and css.

If you are familiar with html or css your options are virtually limitless for the actual output of the Latest Series Template tag. Note that you can also control the size (width) of the series icon via the " Series Icons Options" also on the series options page.

Now that you've got the Latest Series output customized on your series options page you've got to insert code somewhere in your theme. There's actually TWO ways to do this. The easy way is if your theme is widget enabled you can simply use the super-duper "Latest Series Widget" that comes with Organize Series! The slightly harder way is to simply insert <?php latest_series(); ?> wherever you want the latest series stuff to show up.

For instance, most implementations of this information will be in the sidebar of your blog. In my case I simply followed the style of my sidebar (<ul> and <li>) and inserted the code appropriately in it's own block - like this:

<?php if (function_exists('latest_series')) { ?>

<li id="Latest-Series">
    <h2><?php _e('Latest Series') ?></h2>
    <ul class="no-splitted">
        <li><?php latest_series(); ?></li>
    </ul>
</li>

<?php } ?>

Notice how the entire "latest series" block is surrounded by the conditional <?php if (function_exists('latest_series')) statement. This is good coding practice to follow whenever you use template tags from plugins so if you have to disable a plugin or are testing things you won't disable your blog too. Note as well, that this code is based off of how my theme's sidebar is structured. When inserting <?php latest_series(); ?> on your own blog you'll want to follow the html structure in your theme.

Finally, here's how the latest series block looks on one of the iterations of my blog using the above procedure:

\

Now the latest_series(); function also has other parameters you can use to control what gets returned:

$display

This defaults to true.  If you set $display at  false then the latest_series() function will just return the data rather than echoing it.

$args

This parameter controls what gets pulled from the database for the latest series.  It is an array with the following data:

'orderby': defaults to 'post_modified' - This controls how the series are ordered in the returned dataset. It can be post_modified date, post_date, series name, series slug, id, or term id).  Post modified and post date will be taken from the latest or earliest post added to the series depending on the order (ASC or DESC).

' order': defaults to ASC - Whether the data returned is ordered ascending (ASC) or descending (DESC).

'postTypes': defaults to 'post' - This gives the ability to only return the latest series in a specific post types (really useful if you have custom post types on your blog/website).  If you want to indicate only one post type then make sure you surround it in quotation marks - i.e. '"post"'.  If you want more than one post type to be included then surround each in quotation marks and separated by commas - i.e. '"post", "custom_post_type"'.

'hide_empty': defaults to true - If true, then empty series will not be returned.  If false, then empty series will be returned.

'number'defaults to 5 - This simply indicates the number of "latest series" you want fetched from the database.

Example:

Let's say we want to echo the latest 3 series, ordered by series name, in ascending order, with no empty series, from the 'post' post type, and our 'apple' custom post type.  Here's how the latest_series function would be formed.

<?php 
$args = array( 
    'orderby' = 'series_name', 
    'postTypes' = '"post", "apple"', 
    'number' = 3 
); 

latest_series( true, $args );