Photos from Facebook

Use your Facebook photo galleries on your WordPress-based site.

This past summer, I built a simple WordPress-based website for a friend of mine’s business. A designer/developer wanted $8K to build the site and he just couldn’t see spending that much money. While I know that the site I built for him isn’t nearly as polished as what the designers would have created, it certainly meets his primary needs: to provide basic information about his business to people who need it. You can see and judge for yourself here.

WordPress is an excellent tool for building Web sites. What I like about it is that once the site has been set up with the design and features needed, anyone with Admin access can modify its contents. That means that when he has a price change or hours change or some other change, he can go in and change it for himself. No need to bug me or wait for me to get around to it.

But what’s even better than that is the multitude of plugins available to add or enhance content.

Here’s an example. My friend has had a Facebook presence for some time now and his company is “liked” by a considerable number of people. They frequently check in to see what’s new. Yesterday, I helped him add about 10 photos of some work he’s been doing. The photos on Facebook were a big hit with his Facebook friends. I wanted to add the photos to his website. I poked around the plugin directory at WordPress.org and found one called Facebook Page Photo Gallery. This was even better than I’d hoped: it would take the photos I’d already uploaded to Facebook and present them on his WordPress-based site.

I decided to test it here before I went live on his site. I soon discovered that it works only with public photo galleries on Facebook — which meant it would not work with my personal Wall photos. (It probably would if I could figure out how to tweak the settings on Facebook, but I really don’t think it’s worth the bother.) It would, however, work with the Wall photos for Flying M Air‘s Facebook page. And it worked very well, as you can see here:

Did you notice that when you point to an image, it displays the caption?

This is a huge time-saver for me. Rather than have to re-upload and arrange the photos on the website, I can enter a WordPress shortcode with a few variables and a wonderful image display is created automatically. What else could I ask for?

Turning Off a Plugin’s Update Reminder

Hacking it might be better than ignoring it.

Plugin Needs UpdatingOne of the cool features of the Dashboard and administration panels in the current version of WordPress is its reminders of comments awaiting modification and plugins requiring update. You’ll see the reminders as numbers inside red circles. The one shown here, for example, is telling me that one of my installed plugins has an update available.

Clicking the Plugins button on the administration panel’s navigation bar displays the details. In this case, it’s a list of plugins, with a yellow bar indicating the available update:
Update Available

If you’ve been following the posts about WordPress on this site, you might recall that I had a problem with this particular plugin, Landing Sites. In fact, I’d already updated it on my blog and discovered that the update didn’t work. So I’d reinstalled the older version. As a result, WordPress is no nagging me to update to a version I don’t want to use.

A stronger person would simply ignore the update flag. But why do that if you can turn the flag off for this plugin?

Here’s the trick.

  1. Use WordPress’s built-in plugin editor to open the plugin file you don’t want to update for the current version.
  2. Locate the line near the beginning that begins with the word Version: and includes the current version number. Here’s what it looks like for the plugin I’m hacking:
    Edit Plugin
  3. Replace the version number with the current version number. So, in this example, I’d replace 1.3 with 1.4.1.
  4. You can then get a bit fancy and modify the Description area to note the real version number, just in case you forget. This information will appear on the Manage Plugins administration panel as a reminder. Here’s what my fully edited Description and Version look like:
    Edit Plugin
  5. Click the Update File button to save your changes.

Manage PluginsIf you did all of this right and didn’t edit something you shouldn’t have, WordPress will think you have the current version of the plugin installed and the reminder icon will go away. As shown here, the version number and description in the Manage Plugins administration panel will reflect your changes.

Best of all, if another update comes out, WordPress will still notify you about it.

Why WordPress Plugin Updates Aren’t Always a Good Thing

When updates go wrong.

Way back in 2006, I wrote an article titled “Reader Engagement Site Improvements.” In it, I detailed a number of plugins I’d installed to help keep visitors around a while longer, looking at new content on my site.

Landing Sites in ActionOne of these plugins is called Landing Sites. Its job is to check to see if a visitor has arrived (or “landed”) on your blog from a search engine it knows. If it has, it displays a custom message with links to possibly related posts. The idea is that if a visitor has come to your site because he was searching for something, maybe one of your other related posts might meet his needs. Here’s what it looks like on my blog, with some customization.

I used the plugin on both my main blog, An Eclectic Mind, and this Maria’s Guides site. It worked like a charm. My blog was even commended by another blogger for the use of this feature. (Wish I could find the link, but I can’t. Sorry.)

Then, I made a fatal error. When WordPress notified me that the Landing Sites plugin had been updated from version 1.3 to 1.4.1, I allowed it to automatically install the update. I didn’t realize until I updated my blog to WordPress 2.7 and changed the theme that Landing Sites had stopped working. Instead of showing a list of related posts, it was show some raw and ugly PHP code.

I figured the problem was with WordPress 2.7, so I just disabled it on my blog. I posted a comment in a WordPress.org support thread and waited for a response. The author of the plugin subsequently posted instructions for a fix, but it didn’t work for me or for others.

Today, Lorelle (of Lorelle on WordPress fame) e-mailed me to point out that the plugin wasn’t working on this site. (I admit it: I’m lazy and still have this site set up on WordPress 2.6.5.) That surprised me. I went into action, beginning the troubleshooting process.

No fix worked. But I was able to track down the old version of the plugin. I disabled the current version and deleted it. Then I reinstalled the old version (1.3) and activated it. The result: problem solved.

I then went to my blog, which is running WordPress 2.7, and installed the old version there. As you can see from the screenshot above, it works.

What does this mean to self-hosted WordPress users? Unfortunately, it means that plugin updates don’t always make things work better — or even right. In this instance, the plugin author “broke” the plugin by trying to fix it and releasing an update. I don’t know if the new version works for everyone else, but I know it doesn’t work for me. I don’t know why, and frankly, I don’t care. I’m just glad that reinstalling the old version fixed the problem.

I like the plugin and am glad to have it fully functional on my blogs.

A big thanks to Lorelle for contacting me when she found the problem. Since I never reach my blogs via a search engine, I probably never would have found the problem on my own.

Upgrade WordPress Plugins Automatically

One of the great new features of WordPress 2.5.

One of the challenges of keeping a WordPress blog running smoothly is making sure all installed plugins are updated promptly when new versions become available. WordPress 2.5 makes this easier than ever by adding an Automatic Upgrade feature.

As shown in the following illustration, the a note in the Plugin Management administration panel indicates that the Bad Behavior plugin (which I rely on to keep the spambots off my blogs) has been updated.

Plugin Management

I have two options for bringing my blog up to date:

  • Download version takes me to the Bad Behavior page on the WordPress.org’s Plugin Directory so I can read about and download the update. This functionality has been around for a while — at least since WordPress 2.3 — with all plugins that support it.
  • Upgrading a PluginUpgrade automatically takes the update process a step further. When I click this link, WordPress automatically downloads, uncompresses and installs the new version of the plugin for me. It displays its progress as it works, as shown here, and confirms that the upgrade has been successful.

I’ve been using this new feature for a few weeks now and it’s worked like a charm. It’s a heck of a lot easier than upgrading the old fashioned way.

RSSImport

A WordPress plugin to add links to RSS feeds.

On pages 165-166 of WordPress 2: Visual QuickStart Guide, Miraz and I discuss CG-Feedread, a plugin that enables you to list the titles (with links) of posts on another blog based on RSS feed content. We use the plugin on our >WPVQS.com Web site to list content from Miraz’s Mactips.info site and my An Eclectic Mind site.

I hate to admit it, but I never really liked that plugin. It came as part of a package and I was only interested in that one part. So today, while attempting to add the same feature to two of my WordPress-based sites, I looked for a different, simpler solution. And I found it: RSSImport by Frank Bueltge.

RSSIMport in ActionRSSImport is a one-trick pony. It enables you to add a list of posts from any RSS feed. There are four options: the number of posts to list, the URL of the feed, whether the list should include descriptions, and whether the post title should be truncated to 30 characters.

You install and activate the plugin like any other plugin. (You can refer to Chapter 7 of our book or consult the documentation that comes with the file if you need help.) Then place the following code in your template file — most likely sidebar.php — where you want the list to appear:

<?php RSSImport(10,"http://feeds.feedburner.com/mariasguides",false,false); ?>

The options go between the parentheses. In this example, I’ll pull 10 posts from the Maria’s Guides feed, exclude the description, and disable the 30-character limit on posts. The result looks like this on An Eclectic Mind. As you can see, I included a heading before the code so the list would blend in with the rest of my sidebar content.

And if you look on the Maria’s Guides site, you’ll see a similar list for an Eclectic Mind. (The two sites used to be one and they’re still somewhat “joined at the hip.”)

I recommend the plugin if you’re looking for a simple solution to list another blog’s posts. But if you want to list multiple blogs’ posts in the same list, CG-Feedread is probably a better solution.

Deleting Spam from Your WordPress Blog

Marking it as spam isn’t enough to get rid of it.

One of the things I like about WordPress is that it’s impossible to know everything about it. And today I learned something new.

I learned that the spam comments that I marked as spam had not been deleted from my WordPress database. They were just marked as spam so they wouldn’t appear in posts.

How did I discover this? I had to export all blog posts from An Eclectic Mind to a special WordPress-compatible XML file that contained all blog posts and comments. I had to weed out all the posts and comments I didn’t want to import into my new Maria’s Guides site. And that’s when I found all the nasty spam I’d marked for the past 4 years.

Now don’t think this was all of the spam. It was only the spam that was marked as spam using WordPress’s comment moderation feature. When the comment spam situation got out of control, I enlisted the help of the Bad Behavior and Spam Karma 2 plugins. Bad Behavior prevents potential spambots from posting comments at all. Spam Karma catches 95% of the spam that gets past Bad Behavior. I’m left with less than 10 spam comments a day. Not bad when you consider that Bad Behavior alone caught 17,067 spam attempts in the past seven days. The way I see it, anyone with a relatively well-Googled blog who doesn’t use at least one of these tools is doing a lot more comment moderation than they need to.

So there I was, halfway through the process of deleting non-book-related posts and their comments from an XML file, when I realized that much of the file’s contents was spam that wouldn’t appear when I imported it anyway. And that’s when I started thinking about how much database space was devoted to this spam.

The DB-Manager Plugin

Database ContentsI use Lester ‘GaMerZ’ Chan’s DB-Manager plugin. This plugin puts MySQL database features into the WordPress administration panel. This is a must-use for anyone who needs to get into their database and learn more about it or make changes to it.

So I went into the plugin’s interface and learned that my blog had 1900+ comments. I knew that only 1400+ comments were actually appearing in the blog. That made 500+ spam entries sitting in my database, taking up disk space and making my backups much larger than they needed to be.

(Note: The screenshot here shows the database contents after removing the spam. If I’d known I was going to write about it here, I would have taken more screenshots.)

I wanted them out.

Help on the WordPress Forums

I found help on the WordPress forums. They really can be helpful if you enter the right search phrase.

The topic was Support › deleting over 10,000 spam comments without using moderation page. The story was, this poor soul had left his blog alone for a week and, when he returned, found 10,000 comments on it. He wanted to delete them.

A member named bindanaku came to his rescue with a MySQL query:

DELETE FROM wp_comments WHERE comment_approved='0'

This assumes that you want to delete all comments that haven’t been moderated. This was not the case for me. I wanted to delete all comments that had been moderated as spam. I assumed that the correct query for my situation would be:

DELETE FROM wp_comments WHERE comment_approved='spam'

I was right.

Back to DB-Manager

Enter a MySQL QueryI went to the DB-Manager administration panel and clicked the Run SQL Query button. That gave me a window where I could enter my query, as shown here. When I clicked Run, I got a message that the query was successful.

Sure enough, when I checked the Database info (see previous screenshot), I could see that 500+ comments had been removed from the database. But the table size was the same.

I used DB-Manager’s Optimize DB feature to optimize the database. That dropped about 400K from the table size.

I should note here that if you’re more familiar with editing a MySQL database, you can do the query with your normal editing tool. I don’t mess with my MySQL database much. I’m always afraid of screwing it up. (Call me a wimp — I don’t care.) That’s why I use DB-Manager.

Conclusion

While all this might seem like a lot of work to get rid of 400K of file size, the situation could be worse on your blog. My blog has about 1500 posts spanning about four years. I’ve been using Bad Behavior and Spam Karma for at least two of those years. So the majority of these old spams were from very old posts. If you don’t use any spam protection software and are manually moderating comments, you could have far more of these spam comments in your database. And since many of them were lengthy listings of porn and ringtone and other URLs, they were quite large in size. If you have a lot of these in your database, it could be taking up a lot of space — perhaps even more than your actual blog posts.

Do I recommend going through this process? It’s up to you.

How I Use the Readers Post Plugin

A brief how-to in response to a visitor comment.

In recent comment on my article about WordPress 2.1 Plugin Compatibility, Julie said that she was having trouble getting the Readers Post plugin to work. I added this plugin to my site a few months ago and wrote about it here. That piece didn’t include any how-to information.

What It Does

The Readers Post plugin by Stefan Groenveld is a three-trick pony that offers the following features:

  • readers() returns a count of the number of people who have read a post.
  • last_posts() displays a list of the most recently read posts.
  • hot_posts() displays a list of the post popular posts, including a reader count.

I use all three of these options on my site. But rather than go into detail about the parameters — you can find that on the plugin’s page; scroll down for English — I’ll provide the code I use as an example.

readers()

This function must be used within The Loop. (If you don’t know what the Loop is, look it up in the WordPress Codex or, better yet, buy our WordPress book, which explains it in detail.) I use it in my post “footer” to display the number of times a post has been read along with a bunch of other stuff. Here’s the code snippet for readers():

<?php if(function_exists('readers')) {readers('Read ',' Times'); } ?>

This code does two things:

  • ?php if(function_exists('readers')) checks to see if the Readers Post plugin is installed. (Actually, it checks to see if the readers() function is available.) If it is available,
  • {readers('Read ',' Times'); } displays the results of the readers() function with the simple before and after parameters I’ve provided.

The result looks something like this — I put a red box around the code’s actual output:

The readers() function in action

last_posts()

I use last_posts() in the sidebar to list the 8 most recently read posts. I find this list of posts fascinating. Each time I visit the site, I look at the list to see what people have been reading. Sometimes I’ll see an old post listed and click the link to revisit it myself. I hope other people find some of the titles intriguing and visit some of my older posts, too.

Anyway, the code I use is as follows:

<?php if (function_exists('last_posts')): ?>
&nbsp;&nbsp;&nbsp;<?php last_posts(8); ?>
<?php endif; ?>

This does the same thing as the code listed above for readers(), but it uses a different syntax for the conditional (if) statement. 8 is the parameter for the number of posts to display.

On my site, this code is enclosed within <ul> and </ul> tags for formatting — most templates use those tags to present information in the sidebar, but your theme may be different. I also put a heading over it to explain what it is.

The result, at this very moment, looks like this on my site’s Home page:

The last_posts() function in action

hot_posts()

I also use hot_posts() in the sidebar. It lists the 8 most popular posts — the ones read most. Keeping in mind how much I love stats, you can imagine how much I like this information. To me, it’s like a horse race, with certain posts racing to have the most hits. When a new post passes an old one, I’m always kind of tickled. (Yeah, I know what you’re saying. What a geek!)

Anyway, here’s my code:

<?php if (function_exists('hot_posts')): ?>
&nbsp;&nbsp;&nbsp;<?php hot_posts(8); ?>
<?php endif; ?>

Again, this code is enclosed within <ul> and </ul> tags for formatting. And since the Readers Post plugin has no way to count posts read before it was installed, I also included a note in small type that indicates when the counts started. I’ll probably remove that count sometime in the future. Here’s what it looks like on my site’s Home page:

The last_posts() function in action

Some Tips

If your blog doesn’t get many hits (yet), I don’t recommend using readers() or hot_posts(). The numbers they display might be depressing. I think (but am not sure) that the plugin starts counting as soon as it’s installed and activated, so you could always add these two functions at a later time and have counts displayed from the installation day rather than the first day the function is used. And site administrator visits are not counted, so you can re-read any post you like without skewing the count.

last_posts() will always be a great addition to the site, almost like a “suggested reading” list for visitors — and a re-reading list for you.

Upgrading WordPress to 2.1: Dealing with Plugin Compatibility

One of the first steps to upgrading.

WordPress 2.1 is out and its a major upgrade to what I believe is the best blogging platform. But your decision to upgrade should be based, in part, on whether you can make good use of the new features. (You can learn more about what’s new on the WordPress.org Web site.) But that’s not all that should be considered when making the upgrade decision. What might be more important is the amount of work your blog may need to complete the upgrade.

Before I launch into my discussion of plugin compatibility as it applies to the upgrade, let me make a clear distinction between the two groups of WordPress users. If you’re using WordPress with a WordPress.com account, you don’t need to worry about upgrading the software. The folks who manage WordPress.com will do it for you and you’ll see the new features online. But if you’re running WordPress on your own server or on a hosted server, you have a bit of work ahead of you to complete the upgrade. This article is for you.

Why Care?

I operate six WordPress-based blogs on a hosted server account. Most of them are “mission-critical,” meaning they could cause loss of business if they were to become unavailable. So I can’t take a major upgrade lightly. That’s why I’m thinking through the upgrade for each site, one at a time, before actually moving forward.

(I do want to mention that if you follow the instructions on the Upgrade page, if the upgrade goes bad, you can always go back to the site the way it was before the upgrade. That’s why its vital to follow the upgrade instructions.)

Types of Plugins

Some of my sites make extensive use of plugins. The way I see it, there are four types of plugins, each of which I’ve given an unofficial label:

  • Simple plugins don’t require any template file modifications and don’t make changes to the way you work with your blog. You just install the plugin, activate it, and it works. Examples of simple plugins include Hello Dolly and No Self Pings.
  • Set-It-and-Forget-It plugins are one step above simple plugins. They don’t require any template changes and don’t make changes to the way you work with your blog, but they do offer an administration panel for setting options. Examples include Bad Behavior, Spam Karma, Random Header, and WP-Cron (with WordPress Database Backup).
  • Entry Utility plugins are plugins that change the way your create entries or display them online. These plugins don’t require you to modify your template file(s), but they may change the way you compose blog entries by offering additional options or change the way entries appear online. Some examples include Adhesive, Simple Tags, and WP-Contact Form.
  • WordPress Feature Extension plugins are those that require modification of your blog’s template files to add plugin-specific tags. In many cases, these tags add impressive new features to the site that go far beyond WordPress’s feature set. Some examples include Customizable Post Listings, Landing Sites, and WP-Print, just to name a few. This is by far the biggest group of plugin types and, as you’ll see in a moment, it’s the group that’s most likely to cause problems in the event of an incompatibility.

The upgrade instructions recommend that you disable all plugins before completing the upgrade. With the first three types of plugins, that should be no problem. But with plugins that require modification of your theme files to accommodate plugin-specific tags, turning off the related plugin could result in PHP errors or other problems when the page is loaded. If you don’t turn off the plugin and upgrade and the plugin is not compatible with WordPress, you could wind up with PHP errors, too.

Which Plugins are Compatible?

My advice is to make a full assessment of your plugin situation before beginning the upgrade. Here’s how:

  1. Go to your Plugins Management page (/wp-admin/plugins.php from your blog’s main directory; click the Plugins button in the Dashboard or any other administration panel) and make a list all plugins that are installed and activated, as well as any that are installed and disabled but might be activated in the future.
  2. Compare the plugins on the list to the WordPress 2.1 Plugin Compatibility page.
  3. Check off all plugins on your list that are known to be compatible. These are the ones you won’t have to worry much about.
  4. Circle all plugins on your list that are known to be incompatible. These are the ones that will need to be permanently disabled. If they are WordPress feature extension plugins (as defined above), you’ll have to find and remove related tags that you may have inserted in your template files.
  5. Put a star beside all plugins on your list that are either not listed on the Compatibility page or are lists with unknown compatibility. These are the ones you’ll have to watch.

Proceed with Caution

There are two ways to insert plugin-specific code in your WordPress blog:

  • With If-Then logic uses PHP IF statements to determine whether a plugin’s function exists — in other words, if the plugin is enabled and its code is accessible by WordPress — and, if it does, allows WordPress to access the code. Here’s an example I use in my sidebar with Readers Post:

    <?php if (function_exists('last_posts')): ?>
    
    <?php last_posts(8); ?>
    
    <?php endif; ?>
  • Without If-Then logic simply inserts the code without any test to see if the function called is available. For example:

    <?php last_posts(8); ?>

You should be able to see which one is safer — the first one. If your template files include plugin-specific code with if-then logic, when you disable your plugins, your blog pages will continue to display without the plugin-specific content or PHP errors.

My advice, therefore, is to go through all your template files and modify plugin-specific code to include if-then logic as illustrated above. This will make it far easier to disable all plugins before the upgrade and turn them back on, one at a time, when the upgrade is finished — as recommended in the Upgrade instructions document.

A Final Word of Advice

While the new features of WordPress 2.1 sound great and you may feel as if you just “can’t wait” to upgrade, don’t just dive in. Think things through. If you have multiple WordPress blogs, perform the upgrade on the blog that’s the simplest, with the least template modifications, and the least “importance.” Follow the upgrade instructions carefully. And be prepared to restore to your current version of WordPress if you need to.

More upgrade tips to come. Keep checking in.

Stop Pinging Your Own WordPress Blog!

A problem resolved becomes a new problem to resolve.

A while back, I complained that the ping and trackback features on my site wouldn’t work. I could get trackbacks and pingbacks, but I couldn’t send them. I even wrote a TrackBack Troubleshooting post about it which has become one of the most widely read posts on my site.

A while later, I moved my blogs to GoDaddy.com. Immediately, the trackback/pingback feature began working. And it’s been working ever since.

Trouble is, when I refer to a older blog entry in my own blog from a new blog entry, the new entry pings the old one, thus creating a trackback “comment.” The comments are ugly and relatively meaningless. Yes, they do provide a forward link to the new and related content, but they also appear in my recent comments list, thus making it look as if I’m the only one who ever comments on my posts. (Not true, but it certainly feels that way sometimes.) And I’m not convinced that the forward link is necessary.

So today I searched the help forums at WordPress.org to see if there was a solution. The answer appeared in a topic titled “How do I stop links to other posts in same weblog producing a pingback?

There were actually several answers. The simplest was to omit the domain name from the link, creating a relative path:

To summarise, when linking to your own posts, use a relative path, not the full path.

So instead of

I wrote this yesterday

Use this:

I wrote this yesterday

Do that, and you won’t get a ping.

Sounds like an easy enough solution.

But my solution of choice was to use the No Self Pings Plugin available from blogwaffe.com:

Some people really like that WordPress sends pings from your own site to your own site when you write posts; it lets them easily leave a trail of related posts.

Some people do not like this behavior; it clutters up their comments.

So here’s a plugin to disable self pinging.

Two ways to do the same thing. Take your choice.

Now if you’ll excuse me, I need to delete all the self-pings that have accumulated on this site in the past few months.

How to List Random Posts in a WordPress Blog’s Sidebar

Draw people into your blog by showing them other posts in the same category.

People browse blogs all kinds of ways. One way is to come in at the Home page and browse what’s there, then click a category link in your navigation bar to go deeper into the site. Clicking a category link identifies a topic that interests them. But how can you get them to keep browsing what’s there when all they’ll see is the few most recent posts displayed there?

imageOne way is to display a random list of category posts in the sidebar (see screenshot right or visit this page for an example). There are a number of ways to do this, but the quickest and easiest (which is usually my preferred method) is to use the Customizable Post Listings plugin by Scott Reilly with a few simple lines of code inserted in your sidebar.

Customizable Post Listings isn’t new. Its latest version (1.1) was released back in 2004. But it still works like a charm — at least in WordPress 2.0.4 on my server. From the description:

Display Recent Posts, Recently Commented Posts, Recently Modified Posts, Random Posts, and other post listings using the post information of your choosing in an easily customizable manner. You can narrow post searches by specifying categories and/or authors, among other things.

I already use it on aneclecticmind.com to display recent posts and recently commented posts, so adding another feature that takes advantage of this plugin wasn’t a big deal. In fact, it made sense.

I won’t go into details about how to download and install the plugin. You can figure that out for yourself. If you’re new to WordPress and plugins and need help, I will plug the book I co-authored with Miraz Jordan here: WordPress 2: Visual QuickStart Guide. It has a whole chapter dedicated to plugins. Enough said.

Once the plugin has been installed and activated, open your sidebar.php file (or the file in which you want to include the random post code). Then enter the following code where you want the list of random posts to appear:

<?php if (is_category()) { ?>
<h2><?php single_cat_title('Random Articles in '); ?></h2>
<ul>
<?php c2c_get_random_posts(16,"<li>%post_URL%</li>", $wp_query->query_vars['cat']); ?>
</ul>
<?php } ?>

Keep in mind that this code uses the tags I use in my sidebar for formatting: h2 for sidebar headings and ul for an unordered list. Your HTML formatting may differ, so you might have to adjust this a bit for your site.

The first and last lines of this code provide conditional instructions. They basically say that if the page being displayed is a category page, show the random posts listing. So if the Home page or a single post page is displayed, the random category list does not appear.

The single_cat_title tag is a neat way to customize the heading so it displays the name of the category.

You might also want to change the value in the c2c_get_random_posts tag. I have it set to show 16 posts; you can show more or fewer. If you put a value in there that’s higher than the number of posts in the category, all of the posts will be displayed in random order. But if you want to display all of the posts, why not do it in reverse chronological order? Just replace

<?php c2c_get_random_posts(16,"<li>%post_URL%</li>", $wp_query->query_vars['cat']); ?>

with

<?php c2c_get_recent_posts(150,"<li>%post_URL%</li>", $wp_query->query_vars['cat']); ?>

Remember to make the value big enough to cover all the posts in each category. I don’t know if there’s a limit to the value, but I probably wouldn’t use this if I had more than a hundred or so posts in a category anyway. It would make the sidebar too long. (My opinion.)

Of course, you might want to change the heading, too — something like

<h2><?php single_cat_title('All Articles in '); ?></h2>

would be more appropriate when showing all the posts.

As you can imagine, there are lots of ways you can play with this to list post titles in the sidebar. And if your post titles are intriguing enough, these few lines of code might keep visitors on your site a bit longer.

More Bad Behavior

I update some software to help keep spammers off the site — and preserve my bandwidth.

Miraz introduced me to the Bad Behavior WordPress plugin some time ago, and after ascertaining that it did indeed work with a GoDaddy.com hosting account (my hosting ISP), I installed it on all of my WordPress-based sites. What I saw was an immediate reduction in the amount of spam that Spam Karma was catching. That wasn’t because it made Spam Karma less effective; it was because less spam was actually accepted by WordPress for moderation. I can verify this by checking the Bad Behavior stats — it catches roughly 7,000 potential spam hits a week on just one of my sites. That means my server doesn’t have to work so hard and, as a result, it can be more responsive to visitors.

One of the drawbacks to hosting multiple sites on a budget is the limitations imposed by my ISP for my level of hosting. I’m allowed 100 concurrent hits — to all sites on my hosting account. I have two very busy sites online and I think they sometimes fight with each other for bandwidth. This hasn’t been a problem until lately — the other day I started getting Error 503 messages (server busy) when trying to access my sites.

I investigated and discovered that at the time I was trying to view my site, Spam Karma had caught roughly 200 spam messages in the span of 3 minutes. No wonder my site was busy. Spam Karma was fighting off spammers. But what the heck was Bad Behavior doing? Sleeping on the job?

I went to the Bad Behavior Web site and noticed an update that should resolve things. More spammer-stopping power. I downloaded and installed it. If the Error 503 messages become less common and Spam Karma catches less spam, I know it’s doing its job.

The point is this (yes, there is a point): if you have a WordPress blog that allows comments, having spam protection is more than just preventing your site from being filled up with spam comments. It’s protecting your bandwidth. And for that, Bad Behavior seems like a good solution. Just be sure that you have the latest version.

And, if you find your spam prevention software helpful, be sure to send a few euros to the developers to keep them interested in keeping the software up-to-date.

December 14 Update: I just did some more research over at Lunacy Unleashed, Web site for Michael Hampton, the developer of Bad Behavior. His article, “Spam Surge,” seems to collaborate what I’ve been experiencing. Apparently, the spam surge also affects e-mail accounts. (My e-mail spam increased considerably about a month ago but has since tapered off to manageable levels.)

One Way to Protect Your E-mail Address from Spammers

Don’t put it on a Web site!

Spammers are nasty, sneaky, conniving people. They use every tool at their disposal to gather e-mail addresses to spam.

Among the tools in their arsenal are spambots — programs that crawl the web and gather anything that looks like an e-mail address, whether it’s in text or part of a mailto tag. Like this: me@spamsucks.com. Or this: Get Info. (I just made those addresses up. Let’s hope they’re not used by anyone, because they’re sure to be spammed.)

So here’s a tip: if you have a Web site, or your company has a Web site, do not put your e-mail address anywhere on it. Doing so will likely get your e-mail address on spam lists. The amount of spam you get will grow exponentially over time, forcing you to spend more time weeding out the spam you receive than actually reading the legitimate messages.

How then, you ask, can people contact you?

My preferred method is with a contact form, like the one used on this site. Here are some painless ways to install a contact form; one of them should work for you:

  • WordPress users can use the WP Contact Form plugin by Ryan Duff to create a quick-and-dirty contact form. Miraz and I discuss this plugin in our book, WordPress 2: Visual QuickStart Guide.
  • Web sites on an Apache-compatible server with PHP installed can use MindPalette’s NateMail, a free contact form that works with PHP. I used this for a while — until I switched to WP Contact Form — and liked it. One of its best features is the ability to use a pop-up menu that lists various people to be contacted. Because the e-mail addresses are not in the Web page, they are protected from spambots.
  • Your ISP may offer a form tool as part of its services. GoDaddy.com, for example, offers form a form mail feature as part of its hosting packages. You create an HTML form on your Web page, include the proper POST command, and GoDaddy sends form content to the e-mail address you specified in the configuration page.

Keep in mind that even contact forms are not capable of keeping out all spam. Some spambots are designed to look for forms and automatically fill them out with spam messages. One way to cut down on this is with a CAPTCHAs feature in the form software. This forces a user to enter the text characters that appear in a graphic image as part of the form. Most (but sadly, not all) spambots are foiled by this additional step, since they can’t interpret the graphic.

Another method for fooling spambots is to encode your e-mail address so it can’t easily be read by the spambot but can be read by humans or Web browsers. This can be something as simple as me at spamsucks dot com or as complex as using special obfuscation software to do the encoding. Personally, I prefer the forms. I’m sure there must be a spambot out there that can read encoded e-mail addresses. But if this is the only option, go with it.

Just get your e-mail address off your sites now. Every minute you waste can lead to more time wasted sorting through spam.

SpamSieve

A spam filter plugin for Mac users.

I don’t know about you, but I’ve been getting a TON of spam e-mail lately — much of it to my .mac e-mail account. Most of it falls into one of a few categories:

  • Stock “recommendations.”
  • Award announcements.
  • Letters from widows or businessmen in Nigeria.
  • Offers for sex-enhancing drugs and devices.
  • Porn sites.

Neither my e-mail server nor my Mail application (Apple Mail) seems able to weed out this crap. So it ends up in my In box for me to manually delete. What a pain in the butt.

Enter SpamSieve. This Mac OS plugin, which works with most common e-mail clients — Mail, Entourage, Eudora, and others — uses Bayesian filtering to identify and weed out spam. You train it, from within your e-mail program, to know what’s spam and what’s not. It works with your Address Book so it won’t mark a message from your mother (or editor or boss) as spam. And it maintains a database of internal rules that help it identify spam — rules you have easy access to and can change at will.

SpamSieve in Mail's Message MenuI installed SpamSieve on my PowerBook yesterday and it immediately began working — even before I had a chance to start training it! Installation isn’t difficult, but you’ll need to follow the instructions in the PDF manual that comes with SpamSieve to get it right. If everything is set up properly, SpamSieve training commands will appear in your application’s menus, as shown here. Then, every time you launch your e-mail client, SpamSieve also opens. It works in the background, moving messages identified as spam to a special Spam mailbox or folder, allowing you to train it to recognize spam or tell it that a message it thinks is spam really isn’t. When you’re finished working with e-mail and Quit, SpamSieve automatically quits, too.

SpamSieve StatisticsInterested in seeing how SpamSieve is doing? You can check out its statistics. Here’s what it looks like on my PowerBook; keep in mind that I check a limited number of e-mail accounts from this computer so it hasn’t had much to work with. The percent accuracy should get higher as I continue training SpamSieve; the manual recommends that you train until it has processed 1,000 messages for the best results.

Now, instead of dreading mail collections, I look forward to them. I’m always curious to see how SpamSieve does. So far, I haven’t been disappointed. It’s doing a better job than my ISP and Mail’s junk filter.

SpamSieve is shareware and costs $30. There’s a 30-day trial period and the software is fully-functional during this time. You can set it up and give it a good tryout for a few weeks before making the small investment in its purchase.

If you do try it, take a moment to stop back here and share your comments about it. I think other readers might benefit from more opinions than just mine.

Random Quotes

I add a plugin to display random “Words to Life By” on my site.

Every once in a while, I’ll hear or read a quote I think is particularly profound and want to share it with others on my site. I’d been doing this for months with the “Words of Wisdom” block near the bottom of the sidebar on the Home page. I listed three quotes there — one of which was the First Amendment to the U.S. Constitution, which is rather long. I knew that if I kept adding quotes, the block would be much larger than it should and the quotes would lose their impact.

Enter Random Quotes (or WP-Quotes), a plugin by Dustin Barnes. This plugin enables you to maintain a database of quotes within your WordPress database, using WordPress’s administrative interface to enter and edit quotes. You then place a line of code in a template file (in my case, sidebar.php) to display a random (or specific) quote.

I tweaked my Web site this morning to add this feature and I’m very happy with it. Setup went smoothly, although I did have to fiddle around a bit with the style.css file to get the quotes to look right. (My trick: assign the same style definitions to the quote styles as my sidebar list styles.) Only one quote displays at a time and I’ve set it up to display on the Home page only. You’ll find it near the bottom of the sidebar, under “Words to Live By.”

Now all I need to do is gather some more good quotes.

Reader Engagement Site Improvements

I add a few “engagement” features to this site.

Blogging is more than just using blogging software to create and edit posts. After all, if someone shouts in an empty room, does her voice make a sound? An important part of blogging is to attract and retain readers. That’s where content, SEO, and site design come into play.

I’m a strong believer that once you get a visitor to your site, the site’s overall design can help keep them there, at least for longer than the average 30 seconds. (Read Jakob Nielsen’s books for the sad truth about site/page visit lengths.) You can do this by making sure the site is legible and by including navigation features that make it easy to find interesting content.

I read an excellent article on Connected Internet today: “Best WordPress Engagement Plugins: Make Users Read More Posts“. The author lists several plugins — some of which I already use or have tried in the past — that’ll help keep site visitors on your site, reading more content. I added two of them today.

Readers Posts

Readers Posts is a plugin that offers three features:

  • Within The Loop, indicate how many readers have read a post before you.
  • List the most recently viewed posts.
  • List the most viewed (i.e., popular) posts.

I installed the second of these three options in the sidebar of aneclecticmind.com. It began working immediately, drawing information from the WordPress database to list the ten most recently viewed posts. Refresh the page after a few minutes and the list changes. This site has, on average about 5 visitors online at any time and they don’t always come to the site’s Home page. That, of course, is the drawback of any plugin that lists recently read posts — it only lists the posts that have been read on their own page — not on the Home page or archive page. In a way, that’s a good thing. It means the person reading a post is reading it because he found it via a search engine or used a link on the site to read it. He’s reading it because he wants to read it (or thinks he does; as we all know, search engines don’t always display desired results). That’s more meaningful than Home page reads, which could include lots of articles that the visitor just isn’t interested in at all.

The benefit of this: site visitors are shown a list of articles that other visitors have found interesting. I love this feature because it shows me what people are coming to the site to read and it helps me write more content of interest to visitors.

If you try this plugin, don’t be alarmed when you click the link above and arrive at a German-language site. Scroll down on that page and you’ll find an English-language translation. Although it isn’t perfect grammar (what is?), it’s certainly good enough to understand the installation and configuration process.

Landing Sites

Landing Sites is a very cool plugin that does a bunch of things, when installed correctly:

  1. It checks to see if the visitor was referred to the page from one of several popular search engines. It the visitor has not, it stops working.
  2. It displays a message with the name of the search engine and the search word(s) or phrase used to find the page.
  3. It displays a list of links to posts on your site that also match the search criteria.

What I like about this plugin is that it only displays content if a visitor has arrived at the site by clicking a link in a popular search engine’s results list. I put it at the top of the sidebar, where visitors are most likely to see it when they arrive at the page.

Installing the plugin isn’t difficult, although you really do need to follow the instructions on the page you download it from. If you copy and paste the code right from that page, you’ll need to modify all the single and double quote characters so they’re straight quotes when pasted into your template file. (I didn’t notice this at first and got PHP errors. It was an easy enough fix.) The result is what you see if you happened to arrive at a page on my site via popular search engine results link. You can try searching for Hermosa Ranch Insanity (the test link I used) and clicking the link to content on my site to see what I mean.

The benefit of this, of course, is that if the article the visitor came to read isn’t enough for him, he’s given other possible articles to try. He may or may not follow the links, but at least they’re there for him. You could keep him on the site longer.

Conclusion

Read the Connected Internet article. It tells you more about these two plugins, as well as others I currently use or have tried in the past. You might find overlap among features; pick the plugin you like best. Give them a try and see how they affect your visitor stats.

Reducing Database Queries

I install Bad Behavior and get another tip from its author.

I never quite understood why I would use an excellent and powerful spam prevention tool like Spam Karma with another spam prevention tool called Bad Behavior. I’d been using Spam Karma on its own since I started moving my sites to WordPress last January and it was doing a kick-butt job of keeping my site comment-spam free — over 50,000 individual comment spams caught in the past eight months. Only about a dozen comment spams slipped through during the same period, and they were easy enough to delete manually. I didn’t think I needed anything else.

But Miraz also uses Bad Behavior on her blogs, so I figured there must be something about it that I was missing out on.

Then I moved all my WordPress-based sites to GoDaddy.com. That’s when I was introduced to GoDaddy’s limitation on concurrent database hits: 50 per MySQL database. My introduction came as a WordPress error screen that said my database could not be accessed when I attempted to load a page on aneclecticmind.com. Another try moments later and it worked. I figured that aneclecticmind.com and wickenburg-az.com, both of which get over 1000 visits a week, we most likely to hit that limitation. This was a problem.

I use a plugin called WP-UserOnline to monitor current access to the site. The software displays registered users (normally just me), guests, and bots from legitimate systems like Google, Technorati, and MSN (for example). It also tells me the maximum number of users online at once: 50 on aneclecticmind.com just a week or so ago. But it doesn’t tell me about the spam bots — automated programs that go online for the sole purpose of filling my posts with comment spam. Spam Karma stops the spam, but not before the spam bot gets online and tries to post it. With literally hundreds of spam messages caught and discarded every day by Spam Karma, it was likely that spam bots were accessing my database along with users, filling up my 50 access spots.

When my sites were running on my own computer, there was no limit to the number of concurrent hits to my mySQL databases. So I didn’t really care about spam bots. But now I had a limit and was starting to care very much.

So I looked at Bad Behavior again. It claimed to prevent spam bots from even getting online at my site. Surely that would prevent database hits. It was worth a try.

I installed Bad Behavior per the online instructions. Then I read the Read Me file. It said it didn’t work with GoDaddy.com. I wondered about that. This was a new version (2.0.6) and that Read Me file might not be up to date. So I decided to risk it to see what would happen.

What happened is that it worked. In less than 24 hours, in fact, it has stopped more than 200 spam attacks on just one site.

I wrote to the author of the software, Michael Hampton, certain that I was missing something. Perhaps Bad Behavior and GoDaddy’s settings were fighting under the hood, causing database corruption, etc. But he wrote back to say that GoDaddy.com had probably fixed the settings problem that was causing the incompatibility. It worked because the problem was gone.

Great!

I used the Donation link in the Bad Behavior Administration panel to send the author a few bucks. (Lunch on me, is usually how I phrase it.) In the comments area, I mentioned how well it was working and my concerns about database hits. Michael responded with even more useful information:

Bad Behavior runs as soon as possible during WordPress’s page load, which cuts database access to a minimum. There shouldn’t be more than a couple of queries run by the time Bad Behavior loads.

Another thing you can do to reduce database queries is to enable the WordPress object cache, which is disabled by default. You can do this by inserting this line somewhere in the middle of your wp-config.php file:

define('WP_CACHE', true);

Then WP will cache some common database queries in files on disk, where they won’t generate future database accesses (unless the data changes, of course).

Thanks for your support!

Thank you, Michael, for this useful tidbit!

I’ll institute that today and see how it works. In the meantime, I’m pleased at the performance of the Bad Behavior/Spam Karma pair. And now I understand why Miraz also uses both.

Footnote (added September 21, 2006): I added the above code to my wp-config.php file and got all kinds of error messages. I suspect that it’s because permissions aren’t set up correctly in my wordpress folder. If you try it and everything goes bad, simply remove the inserted line and resave the wp-config.php file. Will provide an update if I have time to troubleshoot the problem. In the meantime, Bad Bahavior has blocked over 500 access attempts in just a few days. Not bad, huh?

Backing Up a WordPress Blog Database

Back it up — just in case.

It happens more often than you think. Your server’s hard disk dies and takes all of its content to byte heaven.

Of course, it never happens when your files are backed up. So by backing up your files, not only do you have a copy of your hard work in case it does happen, but it’s less likely to happen in the first place.

Two good reasons to back up your WordPress database.

These instructions apply to WordPress.com server installations.

Step One: Make sure the Backup plugin is activated.

You only need to do this once.

  1. Log into your blog and display the dashboard.
  2. Click the Plugins button in the navigation bar.
  3. Confirm that the WordPress Database Backup plugin is activated. If it isn’t click the Activate button in its row.
    The Backup Plugin

Note that if the WordPress Database Backup plugin does not appear in the list, you must install it. You can get it from Skippy.net. We explain how to install plugins on pages 152-153 of our WordPress book.

Step Two: Back It Up

You do this each time you want to back up the database.

  1. Log into your blog and display the dashboard.
  2. Click the Manage button in the navigation bar.
  3. Click the Backup button in the second row of the navigation bar.
  4. Backup OptionsIn the Backup administration panel, turn on all of the check boxes on the right side of the window. Keep in mind that you may have more or fewer check boxes than what is shown here. Select the Download to your computer option at the bottom of the window and click Backup! (If you get an error message here that your backup folder is not writable, you must change the permissions for the wp-content folder on your server so it’s writable. We explain how on pages 120-122 of our WordPress book.)
  5. Wait while the backup is created. It might take a while if you have a large blog. Don’t close the browser window while the backup is being created!
  6. Save FileWhen prompted, save the backup file to your hard disk.

You can automate this process by installing the WP-Cron plugin by Scott Merrill. This plugin, which I use on all of my WordPress blogs, can automatically back up your database nightly and e-mail you a copy of the file.

And since I’ve begun using it, I haven’t had a single need for those backup files!

Listing Recent WordPress Posts

Two ways to get the job done.

One of the features I included in my personal WordPress-based site (www.aneclecticmind.com) is a listing of the 20 most recent posts. You can find this list in the sidebar of the Home page.

I created this list with the following code in the sidebar.php template file:

<?php wp_get_archives('type=postbypost&limit=20'); ?>

The type parameter tells WordPress to show individual posts. The limit parameter tells WordPress how many posts to display. You can set this number to anything you like.

I wanted to include this same feature on wickenburg-az.com, a site I maintain with information about the town I live in, Wickenburg, AZ. Unfortunately, that site makes full use of the Event Calendar plugin to display a list of upcoming events in the sidebar. Although the plugin is configured so events to not display on the Home page, it’s impossible to prevent recent event titles from being included when using the wp_get_archives tag — there’s no exclude parameter. And since clicking one of those titles would display a very boring two-line description of the event, I didn’t want those titles included in the list of recent posts.

What’s the solution? Well, I already had the Customizable Post Listings plugin installed on wickenburg-az.com. This plugin offers flexible ways to list posts in the sidebar. All I had to do was figure out the parameters to include all categories except the one set aside for Event Calendar.

I fiddled around with it a bit and came up with this:

<?php c2c_get_recent_posts (15,"<li>%post_URL%</li>",'1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 22 23 24','date','DESC'); ?>

The numbers in the code is a space-separated list of all the categories I wanted to include. I was lazy and just listed all category numbers between the first value (1) and the last (24) even though other values in between are skipped in my category list. Notice that 11 is missing. That’s the category number for the Upcoming Events category used by Event Calendar.

The result was the list I wanted. You can see it in the sidebar of the Home page at wickenburg-az.com.

WordPress as a CMS, Part 7

Creating a Title-less Home Page

If you’re just tuning in, this is the seventh installment of my series of articles about using WordPress as a CMS to build an informational Web site. Throughout this series, I’m talking about a specific site I developed: Flying M Air, a helicopter tour and charter company I operate when I’m not writing and tweaking my Web sites.

I decided early on that I wanted my site to have a static home page that provided basic information about my company. Visitors could then use the links along the top of the page to view more information in other static pages or the links in the right column to learn more about specific tours and other services.

The Andreas theme I’d modified included page links along the top of the page. As I mentioned in Part 3 of this series, I created the pages and used the Page Order option to assign numbers to the pages that would determine their order. The theme automatically listed the pages by name as a row of buttons at the bottom of the header, using the following code:

<?php wp_list_pages('sort_column=menu_order&title_li='); ?>

Remember, the CSS code in style.css is what determines the appearance of the links on the site.

I created a home page, gave it a title of Home, and assigned a Page Order value of 0. That put it at the beginning of the list, right where a Home page button should appear. My Home page included random images (covered in Part 5 of this series) and text with links.

Now I needed to make that page be the page that appeared automatically when someone went to the default page of the root directory — in other words, www.flyingmair.com. I used the Static Front Page plugin by Denis de Barnardy. Miraz covered this plugin in our WordPress book, so I don’t want to go into a lot of detail about it here. I simply installed and activated the plugin, then confirmed that the Post Slug for the Home page was home. My Home page was the static Home page.

This may have satisfied a lot of people, but not me. The problem was, the page title (Home) appeared at the top of the Home page. I didn’t want it to appear at all. So I had one more thing to do.

Like all other Pages on a WordPress-based site, my Home page was displayed with the page.php file. I opened the file and inserted some conditional code (shown in bold type) around the instruction to display the title near the beginning of The Loop:

<strong><?php if (is_home()) { ?><?php } else { ?></strong><h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a> <?php edit_post_link('<img src="'.get_bloginfo(template_directory).'/images/pencil.png" alt="Edit Link" />','<span class="editlink">','</span>'); ?></h2><strong><?php } ?></strong>

Here’s how it works.

  • <?php if (is_home()) { ?> says that if this is the home Page, display what comes next. But that’s followed immediately by <?php } else { ?>, so nothing is displayed.
  • <?php } else { ?> says that if this is any other Page, display what comes next. That’s the title as a H2 heading and link, as well as the icon I’m using for displaying an Edit link.
  • <?php } ?> says to stop acting on the is_home conditional statement; the rest of the content should appear for all Pages.

The result: for any Page except the Home Page, the Page title appears at the top of the page.

I think that just about covers all of the special features I included in Flying M Air’s new WordPress-based Web site. Did I leave something out? Use the Comments link if you think there’s another topic I could cover in this series. Otherwise, I’ll call it quits for now.

But don’t worry; there are plenty of other WordPress-related tips and topics I can share. Keep checking in for more.

And now, can I interest anyone in a helicopter tour?

WordPress as a CMS, Part 6

Adding Print and E-Mail Features

If you’re just tuning in, this is the sixth installment of my series of articles about using WordPress as a CMS to build an informational Web site. Throughout this series, I’m talking about a specific site I developed: Flying M Air, a helicopter tour and charter company I operate when I’m not writing and tweaking my Web sites.

Because Flying M Air’s Web site was designed to be a sort of “online brochure” for my company’s services, I wanted the site’s visitors to be able to print information right from the site’s pages. Unfortunately, printing a WordPress blog page doesn’t seem to come out as pretty as it does on the site. Try it for yourself and see.

Although I could create PDF brochures for every tour and charter, it would be a royal pain in the you-know-what to recreate these documents every time I had a price change. To make matters worse, there was no way to force visitors to download the nicely formatted brochures instead of simply using their browser’s Print command to print what they saw in the browser window.

Clearly, I needed a better solution.

As usual, a plugin already existed to do the job: WP-Print by GaMerZ (AKA, Lester Chan). This plugin enables you to include a Print link or icon within The Loop for each post. When a user clicks the link or icon, the plugin generates a printer friendly page.

WP-Print is pretty easy to use. Just drop the plugin’s print folder into your plugins folder, go into the Plugins Management Administration Panel, and activate the WP-Print plugin.

Print OptionsNext, configure the plugin in the Print Options administration panel (Options > Print). You use the drop-down lists to indicate whether you want the user to be able to print comments, links, and/or images. I turned off images because they looked ugly with the yellow border around them. Click Update Options. You’re almost done.

Open the template file that includes The Loop and insert the following code where you want the Print link to appear:

<?php if(function_exists('wp_print')) { print_link(); } ?>

If you prefer a print icon like I have, no problem. Use this code instead:

<?php if(function_exists('wp_print')) { print_link_image(); } ?>

A word here about the Print icon that comes with WP-Print. It assumes you have a white background. I don’t. So I had to create my own little print icon. (I did the same for the e-mail icon, which I discuss later.) If you have to go this route, make it roughly the same size and give it the same name as the Print icon that comes with WP-Print and stick it in plugins/print/images/ to replace the existing icon.

If your theme uses The Loop in more than one place, you need to insert this code wherever you want the Print link or button to appear. For example, in my theme (Andreas), I had to insert it in index.php, archive.php, and single.php. I could have stuck it in page.php, too, but I didn’t need to, for reasons I’ll discuss in another installment of this series. In my aneclecticmind.com site, which uses the Exquisite theme, I just had to stick it in the post.php file, which is called by all other files that need to display posts. A much nicer solution, if you ask me.

While I was adding plugins and code, I figured I may as well add an e-mail feature. GaMerZ has one of those, too: WP-Email. This plugin enables you to put an E-mail link or button in The Loop for each post. Clicking the link or button displays a form the visitor can use to e-mail the post’s contents to someone else — or himself.

As you might expect, the plugin installs the same way. Put the email folder in the plugins folder and activate the plugin in the Plugin Management administration panel.

Configure the plugin in the E-Mail Options window (E-mail > E-Mail Options). I won’t show them here because they’re too big to display on this page, but they’re pretty self-explanitory. You can get more information in the documentation. Just make sure you select PHP for the Method Used To Send E-Mail if you’re not using an SMTP server.

Of course, when I installed it, I skipped the configuration step, which caused me to do a whole bunch of other work…more on that in a moment.

Now open the template file that includes The Loop and insert the following code where you want the E-mail link to appear:

<?php if(function_exists('wp-email')) { e-mail_link(); } ?>

If you prefer a e-mail icon like I have, no problem. Use this code instead:

<?php if(function_exists('wp-email')) { email_link_image(); } ?>

Remember, I modified the e-mail icon so it would have that silly yellow background that appears on my site.

E-Mail FormNow here’s where I screwed up — and only because I didn’t follow the instructions. I went onto the site and clicked the E-mail button for a post. A form like the one shown here appeared. The only problem was, there was no image in the Image Verification area. Why? Because the version of PHP I was using didn’t support captcha.

If I’d followed the instructions, I would have seen that that feature could be disabled. But I didn’t see the configuration options at all. So I did things the hard way. I upgraded PHP. And let me tell you, it was a scary thing to do. I actually lost all my blogs for about 10 minutes. Then I figured out how to get them back and everything is working fine. As an added bonus, I can now use the captcha feature in Spam Karma, which has cut my comment moderation work down to zilch.

Of course, I soon realized that I could only send one message every few minutes, which made testing tough. I found the configuration options and after slapping myself on the side of the head, adjusted the settings to give the new feature a good testing.

The moral of this story is RTFM — read the FABULOUS manual. (Gotta keep this site PG rated.)

While I’m discussing The Loop (kind of), I want to mention that I disabled the display of comments (and even comments links) in the Loop. I did this by commenting out the php comments_popup_link tag. I could have deleted it, but I was worried that I might need it someday and not be able to enter it back correctly. I already disabled comments and trackbacks in all posts and pages by setting defaults (as we discuss in our WordPress book).

Why did I do this? Remember, this blog is being used as a CMS. Although I could have left posts open for comments, I didn’t want to deal with Comment spam or have site visitors ask questions using the Comments feature. Visitors on the site are able to contact me using a contact form — that’s something we cover in our book so I won’t be discussing it in detail in this series.

In the next installment of this series, I’ll tell you about the site’s static Home page and the trick I used to get it to appear without a heading. Tune in next week!