• Home
  • About Mitch
  • Speaking
  • Articles
  • Contact
  • Home
  • About Mitch
  • Speaking
  • Articles
  • Contact

Digital Strategist

WordPress Developer

Content Creator

Unapologetic Punk

Mitch Canter

  • X
  • Bluesky
  • GitHub
  • Twitch
  • YouTube
  • LinkedIn
Tutorial

50 Days to a Better Blog–Day 9: Resurrecting Old Content

CMDR Mitchcraft

Reading time: 2 minutes

This post is the ninth of an ongoing series entitled “50 Days to a Better WordPress Blog”.  During this time, Mitch will be providing small snippits of code, plugins, and things you can do to make your blog more attractive, attain new readers, and keep old ones coming back time and time again. You can see the entire series here.

I've always wanted to use this photo too - and it's sort of relevant, right? :)
I've always wanted to use this photo too – and it's sort of relevant, right? 🙂

Let’s face it – you’ve been blogging for a long time now.  You’ve got lots and lots of great content, but some of it can get buried in the shuffle.  You tend to have 3-5 posts that get a lot of content, but the rest are just sort of… there.  Freeloading and drinking your Google Juice.  Let’s put them to work!

Displaying Random Content

A simple function can call 5 posts from your entire database and display them.  Typically you’d only want the title, but if you want to add more information then it’s just a simple loop – add to it what you wish (and tweak this code to suit your needs!)

Drop this in your sidebar:

<li class=”widget widget_oldposts”>
<h4 class=”widgettitle”>Old Posts</h4>
<ul>
<?php $recentPosts = new WP_Query(); $recentPosts->query(‘showposts=5&orderby=rand’); ?> <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<li><a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
</li>

The special part is the “orderby” in the query – that allows us to literally pull 5 random articles.

Displaying Random Relevant Content

Random is great, but not necessary relevant.  Let’s specify even further by pulling 5 random posts form the category you’re currently viewing.  Best used as “related articles” under a post, by the way.

<?php $category = get_the_category();  $relcat = $category[0]->cat_ID; ?>
<h4>Older Posts</h4>
<ul>
<?php $recentPosts = new WP_Query(); $recentPosts->query     (‘showposts=5&orderby=rand&cat=’ . $relcat); ?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<li><a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>

The variable calls the global post variable’s category ID, and then displays that as a query variable in the new loop we create.  This allows us to pull content based on the main category a post is inserted in (it will pull in only one category, so multi-category posts will only related to the first category (main category) chosen.

  • A Responsive Menu Solution for WordPress

    A Responsive Menu Solution for WordPress

    Reading time: 3 minutes

    Edited 01/14/14 to work with WordPress 3.8 A few months ago I modified a really cool WordPress template and started using it for my own clients.  As part of the overhaul, I realized that there was no really good way (included) to turn a WordPress unordered list into a menu that would work on a…

    Development, WordPress
  • WordPress 3.3’s roadmap has been set… at least, it will be.

    WordPress 3.3’s roadmap has been set… at least, it will be.

    Reading time: 3 minutes

    Here’s the email I received of some of the proposed changes to WordPress – a lot of them look super exciting (goodbye IE7!) and plenty of them are just amazing.  What’s your favorite? User Feature: Media Uploader (azaozz) · Definitely v1: Integrate Plupload into dashboard. (GSoC project) · Probably v2: Improve our image manipulation and…

    WordPress