Quantcast
Viewing all articles
Browse latest Browse all 5

Genesis Framework — Using Query Args

The following is a short tutorial on adding a custom loop to a page using the Genesis Framework from Studiopress. The tutorial will demonstrate how to create a simple category page using Query Args, a later tutorial will demonstrate how to use a custom template to create a much more powerful loop.

The Query Args Method

This is by far the easiest method to create your own custom loop, for example, if you want to create a page which displays posts from a certain category and has a clean URL, ie www.yoursite.com/wordpress , rather than www.yoursite.com/category/wordpress.

To create your own Query Args powered loop, you’ll want to create a new page, and then set that page to use the blog template in the Page Attributes box.

Image may be NSFW.
Clik here to view.
genesis custom loop

You should now have selected the Blog template, but before publishing the page you’ll want to use Custom Fields to send a particular query to the template.

To do this, scroll down to custom fields and add a new field, with the name of “query_args” (without the quotation marks). This name is important, so make sure you put it in right in lower case and with the underscore.

Image may be NSFW.
Clik here to view.
Genesis custom loop query args

Please click through for the full image.

Now the important part. In the Value section, you can use any query, so long as it’s in a string format, not an array. To start with, you’ll probably want to pass something simple, like a single category. To do that, simply put “cat=xx” where xx is the numerical ID of a category into the box.

To exclude a category, put a minus in front of the ID, and you can take multiple categories by separating them with a comma.

Now for a word of warning, if you plan on using multiple blog pages, taking separate categories, make sure you’ve not excluded anything in the Blog Page settings inside the Genesis Settings page. Instead, use query args to exclude certain categories from your standard blog, and then include them on a different page.

You can also use this simple method to pull in a wide variety of content, such as custom post types (use “post_type=x” where x is the name of the post type) tags, sticky posts etc. For a full list of available parameters, please refer to the Query Posts Function Reference.

That’s it for Query Args. If you’ve got any questions about correct their correct usage, please feel free to ask in the comments section below


Viewing all articles
Browse latest Browse all 5

Trending Articles