WordPress is a great platform, and these days it's getting easier and easier to use it as a CMS (Content Management System); WordPress 3 is a huge step forward in this area, too. A big advantage of WordPress is the ability to have multiple loops, or take full control over what appears in your main loop.

This short tutorial will show you how to get started with a WordPress feature that I don't think I could live without: query_posts().

[h4_underlined] What is query_posts()? [/h4_underlined]
query_posts is a WordPress feature that allows you to manipulate the loop, and even have multiple loops on one page. This is very useful if you want to filter the main loop to display only specific categories, or if you want a custom loop in the sidebar as the main loop on the main page.

Fortunately, query_posts is very easy to get used to. It works almost the same way as the normal loop, found on almost all wordpress theme pages. The following is a very simple set up to start using query_posts:

An important note to remember is that at the end of the function we have used wp_reset_query();, this will help to avoid conflicts with any other loops that you may have on the page.

So, where I have written "..Your content goes here.." is where you can put the standard code found between the normal WordPress loop. For example:

But, obviously, this can be anything you want, using the usual WordPress functions to attract post data.

Then you can put some text, or anything you want to display, if the query_posts() parameters are not met? This would go where I've written "..If the query parameters are not met, the alternate content goes here..".

[h4_underlined] Parameters for query_posts [/h4_underlined]

There are many things you can set in the query_posts() function, here I will show you how to manipulate the categories, but you can find out all of the parameters by going to WordPress' codex site, found here.

To show posts from only one category, and limit it to 3 posts, you would use the following:

As you can see, each trait is separated by a commercial and (&), alternatively, you can set each argument in a row; This technique can be found on the code page.

To exclude a category from your custom loop, you can use the following code:

This code will show 3 posts from each category on your blog, but excludes the category with an ID of 4. You can also take this further by defining more than one category, separated by commas:

[h4_underlined]Conclusion [/h4_underlinedAs you can see, this method has many advantages over the standard loop, and gives a bit of freedom to actually control your WordPress Loops; This can be particularly beneficial for website design Your.

I hope this can help some of you out, and don't forget that you can read more about query_posts() on the WordPress Codex' website, which were found here.