I just whipped up the puniest of WordPress hacks for the ultimate reasons, to serve myself. If I knew what I was doing, it would be a plugin, but I’ll leave that as an exercise for the reader.
Here’s the thing. Whenever I write something, i like to reference by link a previous post. So I have to load my own site to find it, and man, I am tired of waiting. So my hack generates page that just in simple layout lists your latest 100 (or whatever number you wish) posts, so you can either copy the URL or edit it.
It makes something like this:
The code consists of 2 PHP files and a GIF image that go into your theme directory:
http://cogdogblog.com/code/lastposts.zip
headless.php
is just a simplifed version of header.php with just some CSS in itlast.php
is a simple template that does all the workimages/edit.gif
is just an icon for the output
A walk through of the code of last.php follows for the curious… This first part merely provides what WP needs to list it as named template
This is a little bit of useful trickery to make any page that uses this template use a different file for the header, instead of header.php- I use this often when I need to insert custom things in the HEAD of an output page:
Just the HTML set up for lists…
Last Posts!
Now we start the work; we first run a custom query to get the last 100 posts (change the number if you want more or less). This iterates your own version of the WordPress Loop. We set up a while loop so we can walk through each one, and we insert what is yanked from the database for a post, all of the information about/in a blog post.
have_posts()) : $my_query->the_post();?>And here we echo what is needed to display info for one post, link to it, its title, date and time of posting, and a link to edit it (only if you are logged in with edit privs):
- ', ''); ?>
And the rest just closes things up, nice and neat: