Blogging Tip: Send Yourself Blogpost Anniversary Reminders

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, April 23, 2015

Follow me on Twitter as @mattiasgeniar

This is something I’ve tried out for the last 2 weeks, and it seems to be working.

This won’t work for every kind of blog. Mine is very technical and contains quite a few guides, howto’s, debug-quests, … most of these are rather timeless. If they’re true today, chances are they’ll be true next year as well.

But most of that older content goes to die after a week of publishing. New posts come and the older ones disappear. This is where these kind of anniversary reminders of your own blogposts come in handy.

Revisit old content

For me, the benefit is twofold: I’m reminded of the content I wrote 1, 2, 3, … 5 years ago and I can keep it up-to-date. In technology, even though the general outline of a technical post remains the same, the future you may have different views or opinions on how to handle certain situations.

This gives me a chance to re-read what I once wrote, curse at myself for doing it in that particular way, and update the blogpost with more accurate details.

Spread the content again

I’m mostly publishing all of my blogposts on twitter. Facebook is for friends and family, they don’t care about the technical posts I wrote here.

As my follower count grows, it could be interesting to tweet about a 3 year old blogpost again. I probably didn’t have that many followers back then, so I now have a chance to publish the same post to a wider audience. Mostly effortless, as I didn’t have to write an entirely new post.

Those older posts would only deserve attention today if they’re still accurate, so I have to update them to todays standards. And not every post is worth posting again. You have to be selective.

Script: blogpost anniversary reminders

To facilitate me with sending reminders to both myself, and eventually my tweeps, I wrote a little script that mails me daily whenever one of my posts gets to celebrate its yearly anniversary.

<?php

# Parameters
$db_host = 'localhost';
$db_user = 'your_username';
$db_pass = 'your_password';
$db_name = 'your_db';
$mailto  = 'your@email';

try {
  $dbh     = new PDO(
    'mysql:host='. $db_host .';dbname='. $db_name,
    $db_user,
    $db_pass
  );
} catch (PDOException $e) {
  die('Sorry, db connection could not be made. Error: '. $e->getMessage() ."\n");
}

$posts   = "SELECT *
            FROM blog_posts
            WHERE
              DAY(post_date) = '". date("j") ."'
              AND MONTH(post_date) = '". date("n") ."'
              AND YEAR(post_date) != '". date("Y") ."'
              AND post_status = 'publish'
            ORDER BY post_date ASC";

try {
  $rows    = $dbh->query($posts);
} catch (PDOException $e) {
  die('Sorry, query could not be executed. Error: '. $e->getMessage() ."\n");
}

if ($rows->fetchColumn() > 0) {
  $body    = "These posts were published previously:<br /><br />\n\n";
  foreach ($dbh->query($posts) AS $row) {
    $body .= date("Y", strtotime($row['post_date'])) .
              ": <a href='". $row['guid'] .
              "'>". $row['post_title'] .
              "</a><br />\n";
  }

  # Mail results
  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

  mail(
    $mailto,
    'Wordpress: blog post anniversaries! ('. count($rows) .')',
    $body,
    $headers
  );
}

?>

Change the parameters at the top for your own database credentials, enter your e-mail address and add the script to cron.

$ crontab -l
0 9 * * * /usr/bin/php /path/to/post_reminder.php > /dev/null 2> /dev/null

The above sends me an e-mail every day at 9AM, if one of my blogposts has been posted on the same day, one or more years ago.

For completeness sake, here’s the full script. And it’s super short and easy to change.

<?php

# Parameters
$db_host = 'localhost';
$db_user = 'your_username';
$db_pass = 'your_password';
$db_name = 'your_db';
$mailto  = 'your@email';

try {
  $dbh     = new PDO(
    'mysql:host='. $db_host .';dbname='. $db_name,
    $db_user,
    $db_pass
  );
} catch (PDOException $e) {
  die('Sorry, database connection could not be made. Error: '. $e->getMessage() ."\n");
}

$posts = "SELECT *
            FROM blog_posts
            WHERE
              DAY(post_date) = '". date("j") ."'
              AND MONTH(post_date) = '". date("n") ."'
              AND YEAR(post_date) != '". date("Y") ."'
              AND post_status = 'publish'
            ORDER BY post_date ASC";

try {
  $rows = $dbh->query($posts);
} catch (PDOException $e) {
  die('Sorry, the query could not be executed. Error: '. $e->getMessage() ."\n");
}

if ($rows->fetchColumn() > 0) {
  $body = "The following posts were published on the same day in the past:<br /><br />\n\n";
  foreach ($dbh->query($posts) AS $row) {
    $body .= date("Y", strtotime($row['post_date'])) .": <a href='". $row['guid'] ."'>". $row['post_title'] ."</a><br />\n";
  }

  # Mail results
  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

  mail($mailto, 'Wordpress: blog post anniversaries! ('. count($rows) .')', $body, $headers);
}

?>

This script works for me and I’ve gotten value (read: pageviews) out of it. Hopefully you can get the same!



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.