When I celebrated my four years of blogging I also introduced a big problem this blog is facing: there is so much content it’s not easy to find what you are looking for.
I received some interesting suggestions, and one of them is to link all posts of the same series. This is what a reader said: “In the first post, put a link of all the steps (requires manual editing)”.
I found a way to put an index on each post of a series using custom fields, and I am sure you’ll find it interesting. Let’s take Create a Flash game like Rebuild Chile series as example.
I want, in every post of the series, to show the full list of posts of the series. Without a lot of manual editing, of course.
So, that’s what I did: first, for every post of the series, I added a custom field called
Create a Flash game like Rebuild Chile value. The idea is to add a
series custom field to every post in every series with a proper value.
If you don’t know how to add a custom field, here it is a little help:
At the end of the Post page admin, you’ll find the form to add new custom fields. That’s how I added
series custom field. Now, a few lines of code to rule them all… this is what you have to include somewhere inside the so-called WordPress Loop:
<?php $series = get_post_meta($post->ID, 'series', true); if($series): ?>
<div id = "series">
<h2>Read all <em><?php echo $series; ?></em> series</h2>
<?php $chapters = get_posts('numberposts=-1&meta_key=series&orderby=date&order=ASC&meta_value='.$series); foreach($chapters as $chapter):?>
<li><?php if($chapter->ID != $post->ID): ?><a href ="<?php echo get_permalink($chapter->ID); ?>"><?php endif; echo $chapter->post_title; ?></a></li>
<?php endforeach; ?>
<?php endif; ?>
Line 1: Assigning to a variable called
$series the value of the
series custom field value, if any. Then, if there is a value…
Line 5: Creating a
$chapters array and populating it with every post (numberpost=-1) whose
series custom field (meta_key=series) has
$series value (meta_value=$series) ordering them by date (orderby=date) in ascending way (order=ASC). Then scanning the entire array, saving each item into
Line 6: Adding the post title, along with a link if it’s not the current post
The remaining lines are just HTML to let me style the content.
You can see the result in the Create a Flash game like Rebuild Chile series… I have to find the right style but I think I’m on the right way.
Do you like this way to use custom fields?
You will be pleasantly surprised by WordPress Themes provided by Template Monster. All of them are of professional design and high quality.