Query Posts is a widget that allows you to display posts 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. Understanding how the query_posts() function works will help tremendously in setting up this widget.
Set a title for your widget. There's a checkbox in the settings to display this.
Criteria by which you want to order your posts.
The order in which your posts should appear.
A multiple select box that allows you to only display posts with a specific status.
A multiple select box that allows you to dispaly specific post types.
Number of posts to display.
The number of posts to skip over before displaying your posts.
A number that represents a specific page of posts. For example, you could list posts that should only be on page 2.
ID of the parent post for which you want to list its children.
Multiple select box for showing posts with a specific mime type. This is generally only useful for attachments.
Select a custom field (meta) key to list posts by. Only posts with this meta key will be shown.
Select a custom field (meta) value to list posts by. Only posts with this meta value will be shown.
A comparison value to decide how to list posts when listing them by meta key and value.
Comma-separated list of author IDs.
A four-digit year to select posts from.
A select box for a month to show posts from.
A select box for a week of the year to show posts from.
A select box for a day of the week to show posts from.
A select box for an hour of the day to show posts from.
A select box for a specific minute to show posts from.
A select box for a specific second to show posts from.
Check to make sure no sticky posts appear at the top of the list.
Resets the query used to what the current WordPress query is. Use this if you're having trouble is conditional tags in your theme.
Check this to display the widget title at the top of the widget.
Select box for which to wrap each post shown. Note that the "widget" option will make each post an individual widget on display.
An additional CSS/HTML class for individual posts.
Whether to show an image along with each post. If you have the Get the Image plugin installed or a theme that has it packaged, the get_the_image()
function will be used. Otherwise, the the_post_thumbnail()
WordPress function will be used.
The size of the image you'd like to show.
Whether to display the post title.
The HTML element to wrap the entry title in on display.
A shortcode-ready area for showing a post byline under the post title.
Whether to display the full post content, excerpt, or no content at all.
The text to display for the <!--more-->
link when showing the full post content.
Whether to display the paginated list of pages when using the <!--nextpage-->
short tag.
A shortcode-ready text input for displaying post meta information after the post content.
A custom error message to display when no posts are found. This is shortcode-ready.
Comma-separated list of post IDs to show.
Comma-separated list of page IDs to show.
Comma-separated list of attachment IDs to show.
Comma-separated list of category IDs to show.
Comma-separated list of tag slugs to show.
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. All rights reserved.