Proudly Presenting
Eidetic Opacity

Being The Singular Personal Blog and Virtual Soapbox of Alex Leonard

The Category known as WordPress

WordPress Tip: Get the date of your first post

I’m just working on setting up a custom WordPress archive for a client at the moment (displaying posts by academic year).

In order to do things absolutely right (and in case they decide to post-publish older items), I need to be able to check when the first post was published on their WordPress installation.

I figured I’d share the code out here in case someone else finds it useful (and in case anyone can suggest improvements to the code). I’ve wrapped it up as a function so you can throw it your functions.php if it’s something you’ll re-use.

/**
 * Get First Post Date Function
 *
 * @param  $format Type of date format to return, using PHP date standard, default Y-m-d
 * @return Date of first post
 */
function ax_first_post_date($format = "Y-m-d") {
 // Setup get_posts arguments
 $ax_args = array(
 'numberposts' => -1,
 'post_status' => 'publish',
 'order' => 'ASC'
 );

 // Get all posts in order of first to last
 $ax_get_all = get_posts($ax_args);

 // Extract first post from array
 $ax_first_post = $ax_get_all[0];

 // Assign first post date to var
 $ax_first_post_date = $ax_first_post->post_date;

 // return date in required format
 $output = date($format, strtotime($ax_first_post_date));

 return $output;
}

To echo it anywhere on your site just run:

echo ax_first_post_date();

I’m hoping to be a little better at keeping track of useful WordPress functions that could be reused, so have created a sub-category of my WordPress category called “Functions”. If nothing else it will be a useful reference point for me.

Update

As soon as I hit publish I knew I should have held off until I added in a date format parameter. I’ve updated the code now so that you can tell the function what format the date should be returned in (using standard PHP date format).

Date Added: July 27th, 2010 | Leave a comment!

Upcoming: KL, Malaysia plus WordCamp!

So I’ve finally sorted out my shit and booked flights, hotel and my ticket for WordCamp Malaysia. Really looking forward to it, and despite my current workload I’m hoping that I’ll pretty much be able to take it easy for the 4 days I’ll be in Kuala Lumpur. Obviously this is a wholly nerdy thing to be doing, but, well, I don’t care. Clearly I’m a nerd and there’s no getting around it.

I think if you asked me a year ago did I think I’d be attending a WordCamp in the near future, I’d have said yes. However the location behind that intention would most definitely have been Ireland. In fact I had I even had thought about setting up the first WordCamp Ireland, but got busy and never sorted it, instead Sabrina Dent and Katherine Nolan did, by all accounts, an incredible job. Perhaps I’ll make it to the next one. Still, little did I think that I’d be here a year later and prepping for a jaunt to Kuala Lumpur to get my WordCamp fix.

I’m not really sure what to expect as this is my first WordCamp, but I’m sure it’ll be a blast and I’m looking forward to meeting a whole bunch of like-minded developers.

Regarding the event itself, I’d say the presentation I’m looking forward to the most is Aizat’s “Beginning WordPress Plugin Development”, as it’s something I just have never quite gotten round to sorting out, and it’s almost certainly something I should be doing – if nothing else to make my own life easier with reusable functions, and hopefully to give something useful back to the community. There’s lots of other interesting talks lined up as well of course, and you can find more info out over at the WordCamp.my Agenda page.

At the same time I’m very much looking forward to having a look around Kuala Lumpur as it looks like quite an interesting place. I have to read up a bit more on things to do there and if anyone’s got any dynamite suggestions, please leave a comment below!

Date Added: May 8th, 2010 | Leave a comment!

WordPress 3 Upcoming

It’s all getting very exciting in the world of WordPress. Version 3 isn’t a million miles away and includes some fantastic changes!

  1. Menu Management built into core
    WooThemes introduced a menu manager and the WP team liked it so much that they asked if WooThemes wanted to contribute it to the core. It looks solid, straightforward, and very nice altogether.
  2. Mµ Merge
    WordPress is merging the WordPress Mµ codebase. There’ll now just be one version which will do all that you need. This is great news.
  3. BuddyPress for all (not specifically version 3 related)
    BuddyPress is now available as a plugin and works on standard WP installations! Not only that, there’s a new “Template Pack” plugin that ensures you can keep your own theme but get all that BuddyPress goodness.

The future is looking bright for the WP platform!

Read more over on wordpress.org:

Date Added: March 4th, 2010 | Leave a comment!

After the Deadline for Firefox

I recently wrote a review of the elegant WordPress plugin called “After the Deadline”, which is a fantastic tool designed to help you write better articles on your WordPress-based website.

The great news is that this fantastic functionality is now available for writing anywhere on the web through a simple Firefox Extension.

…we’re pleased to announce the release of the After the Deadline add-on for Firefox.

After the Deadline works in text areas on most webpages. Simply push a button F7 or click to check your spelling, style, and grammar no matter where you are.

This add-on has all the After the Deadline features. You can enable the style checker options you use in the preferences and you can ignore errors to prevent them from coming up.

via After the Deadline for Firefox – Released « After the Deadline.

Download After the Deadline for Firefox

Date Added: February 3rd, 2010 | Leave a comment!

WordPress Foundation Launched

Matt Mullenweg from Automattic has just launched a new website called the WordPress Foundation.

From their “about page”:

The point of the foundation is to ensure free access, in perpetuity, to the projects we support.

This certainly sounds good to me. The aim being that WordPress and similar projects will have support to survive far into the future and provide a stable platform for generations to come.

It’s a non-profit organisation and I guess it has similarity to the Mozilla Foundation which was formed to promote and support development of open innovation on the internet. The aim of the WordPress Foundation is to ensure that people will always have an open-source option for publishing content on the internet.

The moment we’ve all been waiting for: the WordPress Foundation is now public. As they say, slow cookin’ makes good eatin’.

via Getting off the ground.

Congrats to Matt and co, and I hope the foundation is a success.

Date Added: January 22nd, 2010 | Leave a comment!

WordPress 2.9 just around the corner

by Wolanka

Image by Wolanka

All you WordPress fans will be glad to hear that the frequently updated and marvellous WordPress is soon to release a new update, WordPress 2.9.

I’ve had a look at the beta on a test install and there’s a few really nice features.

  1. Image Editing
    Yep, they’ve introduced an image editor – something that will, no doubt, prove extremely handy for both myself and clients that have sites run off WordPress. It’s a fairly basic editor – crop, resize, rotate, but that’s all I’d really want it for. Simple and fast!
  2. Post Thumbnails
    There’s been innumerable ways to alter WordPress to include a thumbnail image in your post-excerpt, they’ve now decided to build this functionality into the core. I think this is great as it will make life a little easier.
  3. Easy Embedding
    WordPress 2.9 is now going to support a facility called oEmbed, which is sort of like an open embedding framework supported by a number of large content distributors around the net. There’s a detailed post about it over on Viper Bond’s 1 website: Easy Embeds for WordPress 2.9
  4. Trash
    Not sure about deleting stuff, but annoyed that it’s taking up your screen space? Now WordPress has a “trash” function!

They’re the major new features as far as I can make out – there’s a whole rake of other improvements which will be fully detailed on the WordPress Codex page for the 2.9 release.

  1. I don’t know if this is his real name

Date Added: October 18th, 2009 | Leave a comment!

WordPress get it right (again)

4/5

There’s no surprise that I really like WordPress/Automattic – they just keep on rolling out impressive features and finishing touches which improve the process of publishing on the web. I can’t believe just how far this platform has come in a few years.

What is it this time? Just a really fantastic spell-checking plugin called “After the Deadline”. I’d consider myself  a fairly capable user of the English language, but sometimes stuff slips by. Of course, being a dedicated Firefox user I have an English (GB) dictionary build right into the browser – and whilst this is good, it fails to do some of the things that After the Deadline offers, such as style and grammar suggestions.

Matt speaks about it over on WordPress.com:

After the Deadline will analyse your post as you write it and highlight potential errors with an underline (red for spelling, green for grammar, blue for style), similar to grammar and spell checkers in word processing software. Clicking on a highlighted word or phrase will reveal the suggested correction, tell you why it’s suspected to be an error, and allow you to accept or ignore it.

You can get a better idea about it by watching the following video:

Please enable Javascript and Flash to view this VideoPress video.

If you’re a WordPress.com user, well it’s automatically available to you, and if you’re a self-hosted WordPress user (as I am) you can just add the plugin through your own site or download it from WordPress.org. Self-hosted users will need to pick up an API key over at www.afterthedeadline.com

Does it work?

After the Deadline Settings

After the Deadline Settings

Heck yeah. Writing this post I instantly saw the benefits.

I quickly worked out that I needed to drop in on my profile options screen to enable some of the fancy features that make this more than just a spell checker. After selecting all available options, I was able to see just how useful this plugin is.

In the first draft of this post it suggested that I should avoid a cliché:

Avoid “time and time again

Clichés are phrases used so much they lose their original power. Try revising the meaning of this phrase using your own words. It will make a stronger impact on your reader.

How cool is that? I don’t particularly want to fall into the trap of reiterating tired and worn out phrases, and now I’ve got a way of quickly checking that my English usage isn’t becoming conventional – something most likely to spew forth from a brain addled by a world which encourages “text speak” and diminutive attention spans.

I can also see this being a really nice addition for clients that have WordPress powered websites. My only question is – is there a shortcut key?

Rated 4/5 on Sep 26 2009
Vote on Alex Leonard‘s reviews at LouderVoice

Date Added: September 26th, 2009 | 4 Comments

WordPress: Grouping posts by month/year

I have just been trying to work out how to group posts by year when displaying them in WordPress, something that could come in handy for a portfolio or a section on a website which has posts published infrequently. As I couldn’t find a definite solution elsewhere I thought I’d publish it here in case it helps someone else.

The first clue to how to do this came from Dev Lounge, although their solution uses “the_date” function which allows you to group multiple posts from a single day under one date listing.

However if you want to do this for groupings by year you need to apply a bit of simple PHP and variable assigning.

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<?php
 // Assign the year to a variable
 $year = the_date('Y', '', '', FALSE);

 // If your year hasn't been echoed earlier in the loop, echo it now
 if ($year !== $year_check) {
 echo "<h2 class='year'>" . $year . "</h2>";
 }

 // Now that your year has been printed, assign it to the $year_check variable
 $year_check = $year;
?>

<div id="post-<?php the_ID(); ?>">
<!-- post content etc goes here  -->
</div><!-- end .post-wrap -->
<?php endwhile; ?>
<!-- previous next nav -->
<?php else : ?>
<!-- posts not found info -->
<?php endif; ?>

The same logic should apply to grouping by month - although you might need to tweak the code a little bit!

Date Added: August 27th, 2009 | Leave a comment!

WordPress 2.8.1 Announced

The good people over at wordpress.org have just announced the launch of WordPress 2.8.1.

It’s pretty much a roll up of bug fixes to the 2.8 branch, showing that even with a decent beta and RC testing phase, you just can’t catch all the possible issues!

Great work on getting it out, and here’s to 2.9.

WordPress 2.8.1 fixes many bugs and tightens security for plugin administration pages. Core Security Technologies notified us that admin pages added by certain plugins could be viewed by unprivileged users, resulting in information being leaked. Not all plugins are vulnerable to this problem, but we advise upgrading to 2.8.1 to be safe.

What else is new since 2.8? Read through the highlights below, or view all changes since 2.8

  • Certain themes were calling get_categories() in such a way that it would fail in 2.8. 2.8.1 works around this so these themes won’t have to change.
  • Dashboard memory usage is reduced. Some people were running out of memory when loading the dashboard, resulting in an incomplete page.
  • The automatic upgrade no longer accidentally deletes files when cleaning up from a failed upgrade.
  • A problem where the rich text editor wasn’t being loaded due to compression issues has been worked around.
  • Extra security has been put in place to better protect you from plugins that do not do explicit permission checks.
  • Translation of role names fixed.
  • wp_page_menu() defaults to sorting by the user specified menu order rather than the page title.
  • Upload error messages are now correctly reported.
  • Autosave error experienced by some IE users is fixed.
  • Styling glitch in the plugin editor fixed.
  • SSH2 filesystem requirements updated.
  • Switched back to curl as the default transport.
  • Updated the translation library to avoid a problem with mbstring.func_overload.
  • Stricter inline style sanitization.
  • Stricter menu security.
  • Disabled code highlighting due to browser incompatibilities.
  • RTL layout fixes.

via WordPress › Blog » WordPress 2.8.1.

Date Added: July 9th, 2009 | Leave a comment!

WordPress keeps moving on up

WordPress have just announced the launch of version 2.8 today and I’ve already upgraded thanks to the super handy in-built upgrade tool.

Looks like there’s a heap of nice tweaks and changes but the most noticeable thing on first use was the speed of the admin interface, which definitely feels like it’s moved up a good notch in speed. Other improvements include:

  • Better widget management
  • Theme installing and improved theme editing through admin interface
  • Post management and dashboard display options increased
  • Timezone fixes (you can select your timezone and it handles summer time issues)

They’ve also launched a whole new Widget API. So good work Automattic and the community! Keep the fire burning!

Date Added: June 11th, 2009 | Leave a comment!