WordPress Guy

An easy to remember login address

Sometimes I find it pretty hard to type my WordPress Admin URL… you know “http://blogaddress.com/wp-admin.php” or “http://blogaddress.com/wp-admin/“… that’s too many dashes, points and slashes for my taste :-D.

If your server supports mod_rewrite (most servers do), you can shorten your login URL to just “login” by adding this rewrite directive to the .htaccess file in your blog directory:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^login$ /wp-login.php [L]
</IfModule>

But wait, if your blog’s permalink structure is set to “pretty” permalinks, then, your .htaccess file has some rewrite rules already, in that case just add the RewriteRule directive right after the “RewriteBase /”. Like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
 
RewriteRule ^login$ /wp-login.php [L]
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Make sure you save a back-up copy of the original .htaccess file (if there was one) before making these changes. You can never be too careful.

Also, make sure there isn’t a “login” directory.

Multiple tag / category queries

Did you know that WordPress supports multiple tag queries?

Let me explain. Imagine that you want to see all the posts tagged “music” and “apple”, well it’s as easy as:

http://yourblog.com/tag/music+apple

And if you want to see all posts tagged “music” or “apple” then:

http://yourblog.com/tag/music,apple

The same principle applies for categories.

Note: For those of you not using “pretty” permalinks, then it would be:

http://yourblog.com/?tag=music+apple or http://yourblog.com/?tag=music,apple

The only problem with this is that there is no way (that I know of) for doing such queries except typing the url by hand.

How to display a random ‘Read More’ link

Alert! This tip is more fun than useful.

Ever wanted to display a random “Read More…” link on your blog homepage? Here’s some code that’ll help you do just that.

The strings

Copy and paste this code somewhere in the index.php or functions.php file of your theme (but make sure you paste it before the loop):

<?php $more_strings = array("Read More...", "Keep on Reading...", "Wait! There's more...", "Read the rest of the article..."); ?>

You can add as many strings as you want.

Then change the the_content(); bit to this:

the_content($more_strings[rand(0,count($more_strings))]);

That’s it… Have fun!

Don’t forget your navigation links

Picture this: You’ve been surfing the web for a little while, and end up in this great blog that seems to have lots of useful articles. But wait… There are no previous/next links after the tenth article! You’re doomed. Your only option now seems to be going through each and every category, or each and every month in the archives page.

Sounds stupid, I know, but if I you gave me a penny for every blog I have visited that didn’t have previous/next links, I’d be rich by now. It’s so frustrating!

So remember your navigation links! Here is how to generate them in WordPress:

<?php next_posts_link('&laquo; Older Entries'); ?>
<?php previous_posts_link('Newer Entries &raquo;'); ?>

Category feeds

Did you know that WordPress comes with the ability to publish category feeds? That’s right, you can give that option to your readers by providing them with the category feed. Or, you can subscribe to a blog where you’re only interested in one of the categories. This is what their URL looks like:

If you’re using “pretty” permalinks:

http://yourblog.com/category/categoryname/feed

Or if you’re using query string permalinks (the un-pretty ones):

http://yourblog.com/wp-rss2.php?cat=14

Where 14 is the ID of the category.

You can add this to your archive.php with the following code:

<?php if(is_category()) : ?>
<a href="<?php echo bloginfo("url") . "/wp-rss2.php?cat=$cat" ?>">Subscribe to the <?php single_cat_title(); ?> category</a>
<?php endif; ?>

Cool eh!

Popularity contest plugin and WordPress 2.5

One of my favorite plugins is Alex King’s Popularity Contest. Unfortunately it doesn’t seem to work with the latest WordPress release 2.5, nor Wordpress 2.5.1.

Fixing Problem #1

By doing a little searching on WordPress.org Forums I found this post which explains how to fix the Fatal Error problem I’ve been getting. What you need to do is change the line 59 of the popularity-contest.php file from this:

require('../../wp-blog-header.php');

to this:

require('../wp-blog-header.php');

Ok so, that fixed the fatal error problem, and those of you who had the plugin installed prior to updating to WordPress 2.5 shouldn’t have any other problems.

However, if you’re installing the plugin for the first time you might be getting another error ‘Table ‘database.wp_ak_popularity_options’ doesn’t exist on line: 124‘.

Fixing Problem #2

You can choose to create the database manually like Ken McGuire explains in this article.

That works, but it’s a little complicated, so I came up with my own solution.

All you need to do is open the ‘popularity-contest.php’ file go down to the line 1528 and change this:

if (isset($_GET['activate']) && $_GET['activate'] == 'true') {

for this:

if (isset($_GET['action']) && $_GET['action'] == 'activate') {

You can also download the modified plugin:

Popularity Contest for WordPress 2.5

That’s it, you shouldn’t have any other problems now. Enjoy!

Update:

As Marco pointed out, the solution to the first problem could fill your error_log with warning messages. To fix that change the “require(’../wp-blog-header.php’);” for:

@require('../wp-blog-header.php');