Query Posts plugin author Justin Madlock states “The Query Posts widget was written to allow users that don’t know their way around PHP to easily show posts in any way they’d like. It’s like having a cool WordPress developer as a friend ready to do your bidding.” I agree. It takes many of the parameters of the
query_posts() function in WordPress and allows you to configure them by checking boxes and choosing list items. But like any full-featured piece of code, it has a bit of a learning curve. However, when you get it to work, it is enormously rewarding. I’d like to walk you through just one way you can use this plugin to direct some traffic to your older posts.
Get the Readme File
When you install and activate the plugin, a very helpful file is also uploaded in the same folder. The easiest way to access this file is to open a new browser tab and point it to
http://example.com/wp-content/plugins/query-posts/readme.html, replacing example.com with the url to your WordPress install. It should come up nicely formatted, giving a brief description of each option in the widget. I used it to learn how to configure the widget. Bookmark it so you can find it again.
Create a Category Widget
After you’ve been blogging for a while, you create a body of work that disappears into the archives. Your longtime readers may have seen it, but new visitors don’t know it’s there, and probably won’t go looking for it unless you give them a reason to. We’re going to create a sidebar widget that displays posts from a specific category.
The first step is to go to your Widgets subpanel under Appearance. Locate the Query Posts widget under Available Widgets and drag it into a sidebar. Immediately it pops open and offers you a plethora of options:
Wait! Come back! You can do this. Let’s just take this one step at a time.
Widget Title, Order, Order By
The first field is labeled Title. Type in what you want your widget to be called when viewed on your sidebar. I’m going to call mine Query Posts Plugin Demo. Order and Order by go together. You’re going to create a list–how do you want that list ordered? By date? By number of comments? There’s a huge list to choose from. And once you’ve decided on what determines the order, it’s a simple matter to decide ascending or descending. I’m going to stick with the defaults: Date for Order by, and Descending for Order. So far, so good.
Next, what kind of posts do you want to display? You would think Published would be the only logical choice, but what if you were the really organized type, and wrote your posts ahead of time and scheduled them? You could have a sidebar that said Coming Soon and the titles of the posts you had scheduled. I can’t think of a reason to show your drafts, but maybe you can. Anyway, the choice is there if you want to. This is a multiple select box, which means you can select more than one choice. Hold done the Ctrl key as you click to choose more than one.
In the same manner, you need to decide whether you want to display just Posts, just Pages, or Any that meet the other criteria your going to specify. For this particular example, I’m going to just display Posts. However, my gardening website, ColdClimateGardening.com, has a lot of Pages, so I might want to include Pages as well in a widget there.
Individual Posts By ID
The next two fields, Post and Category, are where some of the real power of this plugin shows itself. You can specify each post that you want displayed, if you want to hand pick them. Maybe you have some all-time greats buried in your archives that you’d like new readers to see. You have to identify the post by its number, which isn’t hard, but it isn’t obvious, either. Go to your Posts panel, and hover your cursor over the title of any post. While your cursor is over the post’s title, look down at the bottom of your browser window. You should see a url that has post=xxxx, where the x’s represent a number. That number is the post ID. If you have more than one post you want to display, separate them with commas when you enter them in the plugin’s Post field. As I said earlier, I’m going to make a Category widget, so I’m not going to specify any posts. I’m leaving it blank.
The Category field is one that I frequently use for my gardening blog. I have categories for certain types of posts, like book reviews or interviews, and I have categories for certain plants that I’ve written a number of posts about. I might display all my book reviews in the weeks leading up to the holiday gift-giving season. I know that I will get a lot of hits about pruning forsythia in mid-spring, so I try to make sure my Forsythia category is displayed in the sidebar at that time. I’m sure you can think of other uses. You find your category ID in a similar manner to finding the post ID, except this time, you guessed it, you go to the Categories subpanel under Posts. Hover your cursor over the category you wish to use, and look at the bottom of your browser window for the number. I am going to use the Image Handling category, which is 5.
Posts Per Page
Let’s move to the top of the second column of options. Our first choice is Posts_Per_Page. I don’t have many posts in my sample blog, so I’m going to leave this at the default of 10. That means up to ten most recent posts that meet the other criteria will be displayed. In my gardening blog, which has well over one thousand posts, I set this to 15.
Offset means number of posts to skip over before you start displaying. For example, I’ve got 20 posts in a gardening category, and I want to display 15. But the five most recent are, well, kind of recent, and they already show up in my Recent Entries widget. So I will set the offset to 5, and it will skip over the first five and start with the sixth. Now if I had set the order to show oldest first, then it would skip over the five oldest. Each of the options affects the other options.
Individual Page by ID, Post Tag
There are a bunch of options I am going to skip, because they really don’t pertain to making a category widget. I will note that Page works in a similar fashion to Post, and Post_Tag works like Category does. If you wanted to show only posts from category X that were also tagged with Y, you could do that. But I don’t want to be that limiting here.
Moving on to the third column, if you have a multi-author blog, you might want to show just one author’s contributions to a category. Again, you need to use the author’s ID, which is a number. If you’ve been following along, you’ve probably already surmised that you go to the Users subpanel, hover your cursor over the author’s name, and look down at the url in the bottom of your browser’s window for the number.
The Date fields would be another way to limit the number of posts in your category widget, say, only those in category X from a certain year. Or, if you weren’t limiting this widget to a certain category, you might only limit it by date. Every September, you could show all the posts from all the previous Septembers you had written posts for. Yes, you could specify the week, day, hour, minute, and second, but do you really want to? You may exclude all posts and show nothing in your sidebar if you’re not careful.
Sticky Posts, Reset Query, Display Widget Title
Let’s quickly go through some more options. If you don’t disable sticky posts, they will still rise to the top of your list. Not sure what effect unchecking the Reset Query box would have, but since it’s working the way it is, I’m not going to change it. Attachments aren’t relevant to my category widget, but, moving to the fourth column of options, I do want to display a widget title (Query Posts Plugin Demo, remember?)
Entry Container refers to the CSS that wraps every entry. According to the readme file, if you choose widget, each post appears as its own widget. Most sidebars use
ul to list their items, so try that first. Skip over Post Class, unless you know you need it. Then think very carefully about whether you want to enable post thumbnails. If you are creating a sidebar widget, how much room do you really have for photos? If you are going to put this widget in a footer, it might work. Furthermore, if you don’t have the Get the Image plugin that Justin mentions in his readme file, and you don’t have featured images (formerly post-thumbnails) enabled in your theme, you will get a fatal error if you leave this box checked. (The worst thing that happens is the rest of your sidebar doesn’t load.)
The entry title is the title of the individual blog post. First, make sure the box is checked if you want the titles of the posts to show. (If you uncheck the box, the following drop down list doesn’t pertain to you.) Then you need to decide what kind of styling to apply to the titles. This is a matter of trial and error, unless you are intimately familiar with the CSS of your site’s theme. On my gardening blog
div seemed to work best, but on the demo site, using the new Twenty Ten default WordPress theme, no additional styling worked best.
Byline, Entry Content, More, Page Links, Entry Meta, Error Message
We’re on the home stretch! Your choices for this column will determine how much of the posts will show. I only want a list of titles for my category widget, so I blanked out the Byline, the Entry Content, and the Entry Meta. When those are not used, the more code, and the page links have no effect. The error message won’t show unless the widget can’t find any posts that meet your criteria, so once you have successfully configured this widget, you should never see this message. I see no reason to change it.
If you haven’t been doing so right along, click the save button in the bottom right corner of the widget, close it, and then view your site. Looking at the demo site, I see more space between the entries than I would like. I have looked at the page’s source code and can’t see any reason for why this should be. It looks right on my gardening site. I hope it will look right on your site, too. Keep in mind that some options can conflict with or modify other options if your widget doesn’t look as expected. The CSS of your theme will also affect the appearance of your widget. I suspect that is what is happening on my demo site. Any suggestions for a fix are welcome.