• 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.

  • Post Ordering Made Easy

    Post Ordering Made Easy

    Reading time: 1 minute

    I love using WordPress’ built in custom post types.   I’ve used them for sliders, directories, galleries, and pretty much anything else I can think to use them for.  The one gripe I have, however, is that I can’t manually set the order of the posts.  Just like typical blog posts, I have to arrange…

    WordPress
  • How to Make a Royally Awesome Author Template in WordPress

    How to Make a Royally Awesome Author Template in WordPress

    Reading time: 7 minutes

    I’ve been trying some new stuff with my client’s websites as of late.  I wanted something where a multi-blog site could get the most out of as few plugins as possible, and still have a really awesome way to display their author’s main information.  But, the information they ask for doesn’t have everything.  What about…

    Tutorial, WordPress