Adventures in teaching wordpress tricks

so I’ve managed to get wordpress to build a list of games from blog posts in my ‘games’ category, here’s how!

No need to cry WP-chan! I figured out how we can be friends again!

first of all, everything here is based off of this, I suck at php and wordpress and my system is just a mod of that. so here goes!


all your ‘codey’ changes happen in one file, just duplicate your “/wp-content/themes/<your theme>/page.php” (I called my new file ‘gamepage.php’).

at the very top of the file, add;

<?php /* Template Name: List of Games
*/ ?>


then, find the line that is something like;

<?php the_content('<p>Read the rest of this page &raquo;</p>'); ?>

it might not be exactly the same parameters, but you’re just looking for the line with the ‘the_content()’ function, and after it, paste:

global $post;
$post_save = $post;
$category_id = get_post_meta($post->ID, 'gl_category_id', true);
$toc = get_posts('numberposts=-1&category='.$category_id.'&order=ASC&orderby=date');
foreach($toc as $post) :
$theIcon = "";
$theDescription = "";
if ( $keys = get_post_custom_keys() ) {
    foreach ( (array) $keys as $key ) {
        $keyt = trim($key);
        if ( is_protected_meta( $keyt, 'post' ) )
        $values = array_map('trim', get_post_custom_values($key));
        $value = implode($values,', ');
        if ( $keyt == 'gameslist_icon' ){
            $theIcon = $value;
        if ( $keyt == 'gameslist_description' ){
            $theDescription = $value;
<Table><TR><TD width=150><a href="<?php the_permalink(); ?>">
if ( $theIcon != "" ) {
    echo '<img src="' . $theIcon . '" width=150 height=150 />';
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
if ( $theDescription != "" ) {
    echo '<br />'. $theDescription ;

(As previously mentioned, I suck at php, so this might not be the most efficient script, but it works)

You’re done playing about with php now! make sure to put this new file next to page.php if you havent done it yet.


next up, head to your wordpress dashboard and make a page, be sure to select the ‘List of Games’ template from the dropdown (the option should be on the right as you are editing the page, if you don’t see it, click on ‘screen options’ at the top right and make sure everything is checked).


Now you need to add a custom field to that page, set the key to be ‘gl_category_id’ and the value to be whatever the number value is for that category (the number is whatever is in the url when you click to display that category if you have permalinks set to default)


And that’s the games list page set up! but you’ll need to do more than that for it to display properly, for your games to appear on this page you must:

  1. Make sure they are set to be the same category as the gl_category_id value of the page
  2. Each games post should have a gameslist_icon custom field, with the value as a url to the icon (unless you change the code, icons will be stretched to 150×150)
  3. Each games post should have a gameslist_description custom field, with the value as a short description of your game


I have noticed issues with cacheing and the like, so if the page doesn’t seem to display how you expect it to, clear your cache, log in again, and refresh the page. 🙂

hope this is useful, and of course it doesn’t need to list games, it could list whatever you use your blog for if you want thumbnails/icons in the list. feel free to comment if you have questions or suggestions or whatever.

3 Comments on “Adventures in teaching wordpress tricks”

  1. I was the person that linked that original site to you on Twitter. Glad it was useful for you.

    No worries about your PHP skills. I definitely consider myself a PHP newbie, but it’s easy enough to hack on it seems.

    Keep up the good work! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *