Modifying the Loop

Normally, the Loop generates a list of posts based on the context of the page being viewed (home page, archive, search results) and your Reading settings. To modify what the Loop displays, you need to change the invisible database query that defines your Loop. The query_posts() function, when called before your Loop, lets you do just that. This function has a huge set of possible parameters:

post_type post_status offset showposts [deprecated; use posts_per_page]

posts_per_page paged caller_get_posts [excludes stickies if true]

post_parent order orderby year monthnum w [week number, 0-53]

day hour minute second post__in [ar ray]

post_not_in [array]

name page_id pagename author author_name cat category_name category_in [array]

category__not_in [array]

category_and [array]

ag_slug_and [array]

ag_slug_in [array]

meta_key meta_value meta_compare [operator]

You can combine most of these arguments to further customize your Loops. I'll demonstrate a handful of the most common Loop modifications. Hopefully, these examples will give you the foundation you need to create your own custom Loops. For more information about query_posts() and all its possible arguments, see

0 0

Post a comment