Archive for the ‘Wordpress’ Category

Wordpress – How to Create an Archives Page

Thursday, March 18th, 2010

To create an Archives Page. You will need to Add a New Page in Wordpress and select to use a template which should be located in your Theme Folder.

Right Click the following file and save as archives.php
archives.php

Upload the archives.php file to your Theme Folder normally located /wp-content/themes/the_folder/archives.php

Once you upload the file, create a New Page and on the Right Hand Column Select Archives for the Template.

Now publish the Page and when you visit the link create by the page you will have an Archives Page with Month Year links to posts create during that time period.

Wordpress – Get Custom Field Inside and Outside The Loop

Thursday, March 18th, 2010

Getting custom fields in Wordpress.

In the Loop: (Results for Posts within the Loop)


get_post_meta($post->ID, 'key name', true); //single result returned in a string

get_post_meta($post->ID, 'key name', flase); //all results returned in an array

Outside the Loop: (Result for Identified Post anywhere outside the loop ie. sidebar, header, footer)

global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'customField', true);

Wordpress – How to Get the Post ID

Saturday, October 24th, 2009

There are various locations throughout your theme where you might need to get the post ID. For instance you may have a widget in the sidebar that needs the ID or some place in the Header or the Footer that needs the ID. The following is a list of different ways to get the ID.

Inside the loop:
This is a Wordpress function for use in the Loop:

the_ID()

or, You can build a function and put in in functions.php

function getthe_loop_postID() {
     global $post;
     $thePostID = $post->ID;
}

In single.php outside of the loop:
You can build a function and put it in functions.php with

function getthe_single_postID() {
     global $wp_query;
     $thePostID = $wp_query->post->ID;
}

or you can use post->ID within the single.php template

If you are going to use post->ID within the header or the footer but want it to display on the single post page. You can use:

if is_single() {
     echo post-ID;
}

or what ever it is you want to do with it.

You can use other SQL commands with the post->ID query as well.

For Example:
If you want to see if the post is a particular post use:

post->ID WHERE ID = 17

For the most recent post use:

$post->ID ORDER BY post_date ASC LIMIT 1

For the oldest post use:

$post->ID ORDER BY post_date DESC LIMIT 1

Wordpress – Unregister all Widgets

Tuesday, October 20th, 2009

In my investigations to fix a problem with a clients site. I found the need to disable a single widget.

The function below will unregister all of your widgets. Use the following code in your functions.php file and refresh or load a page from your site, after that remove the function from functions.php and your finished.

<?php
     update_option( 'sidebars_widgets', $null );
?>

Wordpress – How to Determine the Installed Version and the Database Version

Tuesday, October 20th, 2009

There are a couple of ways to tell what version of Wordpress is installed on your domain. The one I like to use is www.yourdomain.com/readme.html, if your wordpress is installed at the root of your domain. If your Wordpress is installed in a subdirectory you need to instert that in the URL. This read me page will display towards the top the Installed Wordpress version, if you replace all of the files at the same time. You can also log into your Admin section see the version of Wordpress in the bottom right corner of the footer.

To determine the database version you will need to view your database contents. Navigate to the wp_options table (the prefix wp_ may differ in your database) and locate the field for db_version.

Here’s the list for up to version 2.8.4:

2.8.4 = 11548
2.8.3 = 11548
2.8.2 = 11548
2.8.1 = 11548
2.8 = 11548
2.7.1 = 9872
2.7 = 9872
2.6.5 = 8204
2.6.3 = 8204
2.6.2 = 8204
2.6.1 = 8204
2.6 = 8201
2.5.1 = 7796
2.5 = 7558
2.3.3 = 6124
2.3.2 = 6124
2.3.1 = 6124
2.3 = 6124
2.2.3 = 5183
2.2.x = 5183
2.2 = 5183
2.1.3 = 4773
2.1.x = 4773
2.1 = 4772
2.0.11 = 3441
2.0.x = 3441
2.0 = 3441
1.5.x = 2541
1.x = 2540

See the Installation FAQ on Wordpress.com for further information.