|
Helping ordinary people create extraordinary websites! |
WordPress CustomizationBy Justin Laing2008-01-09
The Post Loop So you want a custom loop? The loop is powered off of the current page query. The query is generated by WordPress, typically from your URL. So if your on your site and your at /category1/a-blog-post-with-id-12 the query to get blog post id 12 in category 1. The internal mechanics of how this happens are fairly complex, so we won’t go into them. It’s enough to know that each page has a query generated for it that will grab the correct content for that page. So if you want to customize your loop and grab something besides what WordPress would do by default you need to modify the query before you call your loop. Let’s say you want to put just the 3 most recent blog posts on a page, maybe under some other content. On my site the home page has static content and then displays some recent blog posts. Here’s how you do it: <?php query_posts(”showposts=3″); This does a new query to grab the 3 most recent posts to the blog. I can then display these posts in a normal loop: <?php if (have_posts()) { <div
There are almost infinite ways you can write queries to get the
posts you want for your loop. Visit these two pages for more
information: Tutorial Pages: » Introduction To WordPress » WordPress Themes » Structure Of A WordPress Theme » Making Your New Theme » Modifying The Header » Blog / Post Templates » The Post Loop » Page Templates » Sidebars » Meta Data / Custom Fields For Page Customization Originally posted on Makebeta |
|