Archive for the ‘WordPress’ Category.

Wow.

Check this out: WP-SpamFree has blocked 25,320 spam comments.

And I installed it less than a month ago.

I use Akismet too, but it doesn’t catch nearly as many, and I have to scroll through the Akismet queue. So even though it doesn’t get posted, I have to deal with it. WP-SpamFree just gets rid of it.

Wordpress table hack

If you use Wordpress, you’ve no doubt noticed that it seems to hate tables. Put the code in, and Wordpress pushes it way down on the page. The reason is a bug in the Wordpress engine that inserts paragraph and break tags in your post. I found a solution (but sorry, I don’t remember where, or I’d credit it).

Insert the following code at the bottom of your stylesheet:

.table br, .table p {
display: none;
}

You’ve created a class named “table” (you can call it anything you like). Now, immediately before the table tag, insert:

<div class=”table”>

and immediately after the closing table tag:

</div>

Spam Update

After all the anti-spam tools I’ve tried, the Auto-Close Comments plugin for Wordpress has been by far the most effective. Just thought I’d share with anybody else who’s running Wordpress.

Working!

Usually when I log in in the morning, I have anywhere from 200 - 500 spam comments to deal with (most end up in the moderation queue, so you never see them). Nearly all of them are on old articles, and the autoshutoff plug-in is working well. I didn’t even have one spam comment in the moderation queue this morning. Not one.

Yes! Yes! YES!

Since I installed this plug-in, instead of the usual HUNDREDS of spam comments/trackbacks, I’ve only had SIX. Most spam is on old articles; this plug-in automatically shuts off comments for articles at least 14 days old. Just copy the code below into notepad and save it as autoshutoff.php, upload it to your /wp-content/plugins/ directory, and activate the plug-in from your dashboard! Here’s the code:


/*
Plugin Name: Auto-Close Comments
Version: 0.2
Plugin URI: http://codex.wordpress.org/Plugins/Auto_shutoff_comments
Description: Autoclose comments after 21 days.
Author: Scott Hanson
Author URI: http://www.papascott.de/
*/

/* Add an index on comment_status to wp_posts to speed this up. */

function autoclose_comments() {
global $wpdb, $tableposts;

if (!isset($tableposts))
$tableposts = $wpdb->posts;

// Set $age to the age at which a post should become stale
$age = ‘14 DAY’;

$date = $wpdb->get_var(”
SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL $age), INTERVAL 1 DAY)
“);

$wpdb->query(”
UPDATE $tableposts
SET comment_status = ‘closed’, ping_status = ‘closed’
WHERE (comment_status = ‘open’ OR ping_status = ‘open’)
AND post_status = ‘publish’
AND post_date < '$date'
");
}

add_action('publish_post', 'autoclose_comments', 7);
add_action('edit_post', 'autoclose_comments', 7);
add_action('delete_post', 'autoclose_comments', 7);
add_action('comment_post', 'autoclose_comments', 7);
add_action('trackback_post', 'autoclose_comments', 7);
add_action('pingback_post', 'autoclose_comments', 7);
add_action('edit_comment', 'autoclose_comments', 7);
add_action('delete_comment', 'autoclose_comments', 7);
add_action('template_save', 'autoclose_comments', 7);
?>

Rant While I Wait

Our company from Indiana missed the turnpike and got lost somewhere around Pittsburgh, so while I wait for her, I’ll rant. About WordPress themes. Rather, about WordPress theme designers. And since Jakob Nielsen is the king of making proclamations based on nothing whatsoever but his personal opinion and everybody sucks it up, I figure you can suck this up too.

I’m no graphic designer. I hate Photoshop, and nine-tenths of what it does is meaningless to me (WTF is an alpha channel, anyway, or a path? Why is all that nonsense there?) I realize that lots of these people who put out themes are designers, but seriously, are they blind?

First, most of them are ugly. Either the designers are color blind, and don’t realize that orange text on a black background not only looks stupid but is nearly impossible to read, or they just like ugly. Ugly as in You-gly.

Then, they seem to think everybody wants graphic intensive themes, with little flowery backgrounds all over the page, or a too artistique tulip arching over the top of the page, or something equally nonsensical.

And never mind that they seem to love wasting at least half of the screen with their fixed-width designs. I mean, what’s wrong with these people? It’s a webpage, not a painting. Does “content” even occur to them? What good is a design that’s unreadable? And speaking of unreadable, why is it these designers seem to just love the tiniest little font they can find?

Okay, I’m done ranting. Jakob Nielsen be damned.

Widget Alternative

Widgets are a new WordPress feature. They allow you to drop and drag elements from your admin panel, and that inserts code. Now that I’ve used them on my other blog, I have to say, they are neat (except that wordpress.com won’t let you insert any javascript code). If I ever move my other blog from wordpress.com to, say, here (with another domain name), I will definitely use widgets.

However, if you’re like me, you were inserting code into your site long before widgets came out, and sure, it seems like a pain to start using them. I have an alternative, but first, you should know that changing themes does not affect your widgets. That alone is good enough reason to switch to widgets. You can’t insert any code into a loop with a widget as far as I can tell, though, so the primary advantage is in blogrolls and so forth you want in your sidebar.

Here’s the alternative.

Cut any code you add to your sidebar, and paste it into a new file.Do not include any div tags that assign classes or ids in your new file; instead, leave them in the sidebar.php file, or you’ll create more work for yourself when you change themes and have to change div tags in your own files! Name the file something that makes sense, like my_sidebar_crap.php. In your sidebar.php file where the code was, insert the following:

If you have a number of elements you add to your sidebar, you may want to cut and paste each one into its own file, then use an include statement for each one. That way, if you want to drop one, you just delete its include statement.

The thing, of course, is that when you change themes, you have to open up your sidebar.php file and add the include statements (and you don’t if you use widgets — they move along with your theme). However, this is the best alternative for code you have to add in order to make plugins work (like subscribe to comments, etc.)

Plugins

WP Theme Suggestions

I’m a PHP code jockey, not a CSS geek, so I’ve run into a couple of problems when changing WordPress themes I thought I’d share.

  • If you care about 800×600 standards, check any theme you install. Many themes show horizontal scrollbars at 800×600. If you want to use that theme anyway, and fiddle with the CSS widths, be my guest. If you don’t, switch themes.
  • Check that new theme in both Firefox and IE. A disturbingly large number of WordPress themes “throw” the sidebar under the content — and nobody is interested in telling me how to fix this (on any number of forums, of supposed CSS gurus).
  • Letter spacing works in IE if you specify absolute widths (like “10px”), but not relative widths (like “2em”); both work in Firefox (as they’re supposed to).
  • Sidebars are a pain, simply because everybody does his theme differently from everybody else.
  • Many of the “best” themes (according to whoever rates them in the contests), at least in my humble opinion, are ugly and unreadable.
  • WordPress theme authors for some reason are not interested in expandable width (not necessarily full width) themes.

One of these days, I’m going to get a CSS reference and learn all this DIV stuff so I can write my own.

Oh. And the WordPress forum sucks, period, the end. Don’t bother going there for information. Use google instead.

Misc Theme Changes

First, the quotation at the top, under the header.

I created a class called .quotebar in my css file:

.quotebar{
margin: 0px auto;
border:1px solid #003399;
padding: 6px 6px 6px 6px;
font-weight: bold;
}

I have a random quote script, and have it stored in a separate file, so I needed to include it in the header.php file:

Then also in my header.php file, just below the header div and just above the page div, I called it like this:

Now for the random quote script. The random quote script requires a text file of quotes (it uses line breaks to separate the quotes, so you need to make sure the only line breaks are between quotes). Create a text file and dump whatever quotes you want into it (just watch that line break thing) and call it quotes.txt (you can call it anything you want, as long as you change the filename in the script). Here’s the random quote script:

function random_quote() {
global $textfile;
$textfile = "quotes.txt";
$quotes = file("$textfile");
$quote = rand(0, sizeof($quotes)-1);
echo $quotes[$quote];
return;
}

?>

Bingo, that’s it. Now for the wcol ncol thing.

Equix is set up not to display the whole sidebar when you view a single post. If you have tracker code in your sidebar, you’ll notice your page hits suddenly take a nosedive. Open the single.php file, find the div tag that calls the wcol class, and change it to ncol. You may have to fiddle with the widths for the ncol class in your stylesheet. This should work — as long as you don’t have an image or a table in your main area that’s wider than the specification. If that happens, it will push your sidebar to the bottom.

Code. Is. Poetry.

Damn Quicktags

Anyone who has a Wordpress blog knows about the quicktags, the convenient “code” buttons that appear at the top of the post screen, like those that appear at the top of the comment screen. Trying to change or add to them, however, turned out to be a giant pain in the ass — because, as is so often the case, I couldn’t figure out where they were set.

The quicktag buttons are javascript, not PHP. In your wp-admin directory, there will be a quicktags.js file. That is where you need to add or change the code. For example, I wanted to add a dropcap button. All I did was copy and paste the code for one of the buttons, and change the parameters (note the last line for each button, which is a letter — it’s a unique identifier, and you need to use a letter that hasn’t been used for another button).

Argh!

As much as I like Wordpress, trying to find API info is just a pain in the ass (and the search on the wordpress page doesn’t work). I added the date — but I want the date itself to be a link, so you click on it and it takes you to all the posts for that day.

I got so frustrated trying to find Wordpress info about how to do this (there has to be some kind of function that will), I gave up. It’s just easier to use PHP to do it — and why I didn’t do that in the first place, I do not know.

I’ll do it later. Right now, I’m ready to toss this laptop in the garbage.

Adding A Calendar

I assume you want to add it in your sidebar, so open your sidebar.php file in your theme directory. See how the other items (archives, categories, etc.) are coded; often, they’re in list tags, so replicate the general structure.

Add the following code:

The CSS formatting for the calendar is in the classic theme directory (every Wordpress installation comes with the classic theme). Open it, copy all the calendar code to your stylesheet, then make whatever changes you want.

Do not put the calendar function call inside a loop!

Simple, eh?

A Dilemma

I love technorati. Not only does using technorati tages get me traffic, but I find all kinds of great stuff besides. Remember this read more or read more right here thing?

Author Links

The WordPress support forums are worthless. I have yet to get one useful piece of information from them — and the “search” is the worst part. If you have a wordpress issue, use google. So far, every problem I’ve had (except for the one I’m currently wrestling with, which I won’t go into here, and the problem I’m discussing in this article) has been solved, either directly or indirectly, by googling for an answer.

I use plugins, but I’m more a hack-the-code type than an install-a-plugin type (my favorite plugin is RunPHP, which allows me to run PHP code directly from my articles). Anyway, now that StarWomb is posting here from time to time, I wanted to turn the author name (beneath every article) into a link, so when you clicked on it, you’d get a list of all articles by that author, just like the category (in the same line).