Query Posts is a widget that allows you to display posts and pages in any way you want. It is a revolution in how users interact with their site, allowing them to have the power of more-advanced developers at the tip of their fingertips.
WordPress is a wonderful CMS to work with, but for end users, it can sometimes be a daunting task trying to make things work just they want. Query Posts makes WordPress a more robust, yet intuitive, platform for users to work from.
query-posts.zip
folder.query-posts
folder to your /wp-content/plugins
directory.Basically, it is a wrapper for the query_posts() funtion in WordPress. This is a fairly standard function used, but it requires that end users dive into code to use it. This plugin provides an interface so that the average user can interact with this function without having to learn the intricacies of the query_posts()
template tag and making it work with The Loop.
Query Posts is a widget that allows you to select from several options on what posts you'd like to display. The plugin handles the rest, even the output of your selected data.
There are several settings for the widget. You need to know how the query_posts() function works to use them. You need at least a very basic understanding of its parameters to even use this widget.
Since the widget has numerous settings, I've broken them down into groups to better understand what each does.
Several of the settings are not a part of the query_posts()
function. These are additional settings you may select within the widget controls to choose how your posts display.
get_the_image()
function, you can select this to show a thumbnail.The WordPress Codex splits these parameters into four sections: order, orderby, pagination and offset. But, I like to group them together because each setting can drastically change how the others work.
The post and page parameters deal directly with the type of content you'd like to display. Support for attachments should come in the next major version and custom content/post types in the future.
There's only one sticky post parameter right now. It allows you to exclude or include sticky posts in your query.
The category parameters allow you to display posts according to what categories it is in.
The tag parameters allow you to display posts according to what it has been tagged with.
If you've created custom taxonomies or have additional taxonomies through plugins for your posts, you'll be able to show posts from a specific taxonomy provided its query_var
has not been set to false
(not likely).
If you run a multi-author site, it's sometimes useful to show posts written by a particular author. You can use the author parameters to select those by posts by user ID or user nicename.
To grab posts from a certain period of time, select one or more of the time parameters.
If you use custom fields with your posts, you might like the custom field parameters, which allow you to pull posts by custom field key and value.
meta_value
.This is not required but could be fun to do.
To truly understand how powerful this plugin is, you might want a widgetized page template, or several. My Hybrid theme has one of these. I'll give you a quick tutorial here. For more information on page templates, read this tutorial on page templates.
The first thing you want to do is create a new widget section. So, open your theme's functions.php
file and add this code:
<?php
register_sidebar( array(
'name' => 'Widgets Template',
'id' => 'widgets-template',
'before' => '<div id="%1$s" class="widget %2$s widget-%2$s">',
'after' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title', => '</h3>'
) );
?>
Save your functions.php
file.
Then, you need to create a new file in your theme's root folder named page-widgets.php
. The best method is to copy your theme's page.php
file and mold this code into it. Here is an example:
<?php
/*
Template Name: Widgets
*/
get_header(); ?>
<div class="content">
<?php dynamic_sidebar( 'widgets-template' ); ?>
</div>
<?php get_footer(); ?>
I run a WordPress community called Theme Hybrid, which is where I fully support all of my WordPress projects, including plugins. You can sign up for an account to get plugin support for a small yearly fee ($25 USD at the time of writing).
I know. I know. You might not want to pay for support, but just consider it a donation to the project. To continue making cool, GPL-licensed plugins and having the time to support them, I must pay the bills.
Query Posts is licensed under the GNU General Public License, version 2 (GPL).
This plugin is copyrighted to Justin Tadlock.
2009 – 2010 © Justin Tadlock