WordPress

Enable Drag And Drop Script In Wordpress

Note: This code has been written with WordPress 2.8 in mind. It won't work on versions prior to 2.6 and might have unpredictable results in later versions.

Drag and drop is a useful mechanism to do stuff and can turn a complicated set of buttons or drop down lists into a simple elegant solution.

Wordpress has lots of scripts built in, which do a lot of useful functions. However, they are not enabled by default, which means that in order to get your script to work you need to enable them.

The drag and drop functionality in Wordpress is provided by the Scriptaculous framework. To get Wordpress to include this in your page header just use the function wp_enqueue_script() with the parameter "scriptaculous-dragdrop".

Adding And Updating Options In Wordpress

Wordpress has an options table that developers can use when creating templates and plugins to store information that would otherwise have to be kept in a separate table or written to a file. Assuming the default table prefix of wp_ the options table is called wp_options.

Rather than allow developers to access this table directly, Wordpress has some functions that you can use to create and change options in that table.

To create an option and assign a null value to it use the add_option() function. The parameters are as follows:

Creating A Custom Page Template In Wordpress

There is an easy way to create a custom page for a particular page using Wordpress that doesn't involve adding custom page ID checking code. This might be useful if you want to remove certain aspects of the theme (like a side menu) just for that page. The way this is done is by using the Template Name tag in the following manner.

<?php
/**
 * Template Name: Page Template
 */
?>

Make a copy of your default page template in your theme directory and put this snippet of code at the top. You will now find that when you open the page to edit it there is a section called Page Template. This contains a drop down list of all of the templates available, including the default. You can create multiple page templates by just changing the value of the Template Name tag.

Reset Your Wordpress Password

If for some reason you can't remember your Wordpress password and you can't use the "lost your password" function that comes with Wordpress, due to problems with email, then you can use the following SQL command to reset your password.

UPDATE wp_users SET user_pass = md5('newpassword') WHERE user_login = 'admin';

This can be useful if you have a local web server that you are trying things out on before they go live on the Internet. These servers often don't have access to email as they are just testing platforms and will therefore fail if you try to use the "lost your password" function.

This command has been tested on Wordpress version 2.6.2.

Enable Custom Field Searching With Wordpress 2.6

I have previously talked about enable custom field search in Wordpress, but that involved altering the main Wordpress files, which is a big no-no.

So is there an alternative? Well, yes, otherwise I wouldn't have bothered writing the post! To enable custom field (also called Wordpress metadata) searching you need to set up two things.

First you need to have created a custom field (or two) and added this to a number of posts.

Next, you need to have a custom search form that has the name of the field set as the name of an input box. You don't even need the normal s input box that Wordpress uses as default.

Open up your template functions.php file and add in the following three lines of code.

Display Certain Categories Within Wordpress

If you want to display a Wordpress front page in a new or interesting way by splitting the categories into sections, or by not displaying certain categories at all then you can use the query_posts() function. This function comes as part of Wordpress and allows you to override the queries that are being executed behind the scenes. This basically controls what posts are seen by "the loop". In order for the function to work it must be called before "the loop", look out for this line (or similar):

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

And put the call to query_posts() before that. You will need to give it certain parameters in order to do something.

So what can you do with this function? Well all sorts of stuff, but for this post we are just interested in getting different categories out, so lets concentrate on that.

Fixing Wordpress Scheduled Posts

Wordpress has a neat little feature that allows you to write a post and then schedule it to display at some point in the future. This seems good, but it invariably doesn't work on some server platforms and rather than publishing a post Wordpress just counts the amount of time passed since it was supposed to go live. The basic solution to this is to go into the post and click on publish, which can be a pain if you are taking a couple of days off from blogging and want to leave it running.

The problem lies with the functions that convert a scheduled post into a live post which are kept in the file wp-cron.php in the root Wordpress directory. For some reason the Wordpress developers decided to call the scheduling functions using the fsockopen() function available in PHP. This essentially opens a browser session to the wp-cron.php file, just as you would if you browsed to the location using your web browser.

Wordpress.org

Wordpress is a very impressive blogging platform written in PHP and JavaScript. Impressive in terms of features, ease of use and stability. Wordpress comes with two default templates and two examples plugins, but you can very easily create your own templates and plugins with the Wordpress API.

Looking at the code behind Wordpress there are several classes that it uses to accomplish certain things. For example, Wordpress uses the IXR class from Incutio as a XML-RPC server/client. Doing this saves the Wordpress developers from re-writing things that other people have written so that they can concentrate on the important things.

Procedure For Changing The Directory Of A Wordpress Blog

For many sites the blog is only part of the site, not the main reason for the site existing. In these cases the blog is kept in the directory /blog or similar. Occasionally (for what ever reason) it might be necessary to change the directory. To that end here is a small walk through of the steps you need to take in order to do this.