Archive for the ‘WordPress’ Category

WordPress Upload Management Tip

Saturday, December 17th, 2005

A tip for all WordPress users out there who have unwieldy uploads folders in wp-content: take a bit of the chaos out by creating a bit of a hierarchy in your uploads folder!

Here’s what I do:

  1. Create a folder named “uploads” in wp-content.

    Having a separte folder for the stuff I upload allows me to keep things a bit tidier in there. As you probably know, wp-content isn’t in danger of being overwritten when you upgrade WordPress, and so it’s a good place to stash stuff.

  2. Create folders by year inside uploads to store images, movies, etc.

    If you’re like the rest of us normal folks, you aren’t very good at renaming images that you upload. All that stuff takes a lot of work. However, if you create year-based folders inside your wp-content/uploads/ directory, you’ll be able to start to pin down when you used that really goofy image of your cat.

The only issue with this approach is that you have to make sure to have a new folder on hand when the calendar turns over a new year. If you take the time, though, to make a list of things that you should do every time January comes around again, this is a quick-and-easy thing to add to the list.

One last thing: make sure to chmod all these image folders to 777—otherwise, WordPress won’t be able to work with them!

[Thanks to Amy Qualls-McClure for making this suggestion years ago.]

Alternating Comment Classes

Thursday, July 29th, 2004

This idea expands on something originally done by MooKitty: Comment Backgrounds Hack. Kitty was directly inputting a background in wp-comments.php, but I realized that it made more sense to use an if/else statement and create two classes, comment-even and comment-odd, that could then be styled however the user wished. My end result is like so:

    35  <?php if ($comments) { ?>
    36  <ol id="commentlist">
    37  <?php $i=0; foreach ($comments as $comment) { ?>
    38       <li id="comment-<?php comment_ID() ?>" <?php if($i%2) {echo 'class="comment-even"';} else {echo 'class="comment-odd"';} $i++ ?>>
    39          <?php comment_text() ?>
    40          <p><cite><?php comment_type(); ?> <?php _e("by"); ?> <?php comment_author_l
ink() ?> &#8212; <?php comment_date() ?> @ <a href="#comment-<?php comment_ID() ?>"><?php c
omment_time() ?></a></cite> <?php edit_comment_link(__("Edit This"), ' |'); ?></p>
    41          </li>

Using i=0 as a starting point for the counter allows the logic of if / 2 to work as one expects; the first comment is <li id=”comment-blahdiblah” class=”comment-even”>, etc.

I personally would suggest this as a code change for 1.3+.

[Thanks to Carthik's WordLog for pointing me to MooKitty's hack in the first place.]

Making a Permalink to Daily Archives

Thursday, June 10th, 2004

If you want to create a permalink in WordPress to all entries on a particular day, it’s pretty simple:

<?php echo mysql2date('Y/m/d', $post->post_date); ?>

For me, I put http://ijsm.org/archives/[echo statement] in an anchor I’ve placed this around my instance of the_date to get a permalink that has the date. I suggest adding a title=”Permalink to entries on this date” to the anchor element in an effort to make it clear to your readers what you are doing.

WordPress Plugin: Wonderping

Friday, May 28th, 2004

I have come up with the following WordPress plugin for the pingWondergeeks() function that Rick King wrote back in the day.

Please note: Wondergeeks.net is a closed system. Only users of Wondergeeks need mess with this!

pingWondergeeks() in a Plugin!

<?php
/*
Plugin Name: pingWondergeeks
Plugin URI: http://gfmorris.org/archives/2004/05/28/wordpress-plugin-wonderping/
Description: Notifies wondergeeks.net when a new, public post is made.
Version: 0.1
Author: Geof F. Morris
Author URI: http://gfmorris.net/
*/

function pingWondergeeks() {
        // Rick King
        $client = new xmlrpc_client("/ping/pingme.php?name=[domain.tld]", "wondergeeks.net", 80);
        $message = new xmlrpcmsg("", array(new xmlrpcval("[domain.tld]")));
        $result = $client->send($message);
        if (!$result || $result->faultCode()) {
                return false;
        }
        return true;
}

add_filter('publish_post', 'pingWondergeeks');

?>

Per my convention, data in [brackets] should be replaced by the user.

URL to download wonderping.php. You will also need the wonderping-syndication.zip files to support Wonderpinging.

This code should be saved as wondergeeks.php and placed in /wp-content/plugins/. Before activating the plugin in the WP admin, you need to remove the pingWondergeeks() functionality from my-hacks.php.

Future work for this plugin:

  • Passing more data through the XML-RPC array, thereby eliminating the need for the post syndication file.
  • Adding a function to pass comment data on to wondergeeks.net when comments are made using the WP Plugin API’s comment_post filter, thereby eliminating the need for periodic polling of the comment syndication files.

Thanks to Rick and to Jeff McClure for their help in developing the Wonderping functionality for WP, and to Amy for developing wonderPortal back in the day.

WordPress Backup Shell Script

Thursday, April 29th, 2004

For those seeking to backup their WordPress installations on a nightly basis, I have decided to publish the following shell script.

Below, any instance of a tilde [~] indicates /home/[username]/. Referencing to user root is key to this. You could change it to /home/[username]/ if you so chose.

#!/bin/csh -f

# Determine current date
setenv CURDATE date +%Y%m%d

# Backup all WP databases to compressed, dated file in home directory
mysqldump -q -e -hlocalhost -u[user] -p[pass] [database] | gzip - > ~/${CURDATE}_db-backup.sql.gz

# Backup WP files to compressed, dated file in home directory
cd ~/path/to/wp-files/
tar cf - . | gzip - > ~/${CURDATE}_files.tar.gz

Any data in [brackets] should be filled in, sans brackets.

This should sit in userroot, chmod’d to 755 to be executable.

You will get errors for all files in wp-uploads on the second TAR run for the backups. If you don’t want backups of your WP files but are more concerned about the backup of the database, remove everything from the last comment on down.

I personally get an email sent to me to verify that there were no errors in the running of the script. I also use FTP Voyager’s scheduler to do a Move Down on the backups to a local machine. When I can get a RAID box running at home, I’ll be dumping it to that, since I trust RAID more than a single-point-of-failure HD machine. :)