1001 WordPression Loops

The Loop is the heart and soul of WordPress. It is the one that processes each Post and display to the world wide web what’s been cookin’ behind the WordPress admin panel.

Some quick background reading may be beneficial before proceeding further with designing WordPress Loops.

The following are few models of how the Loop could be applied to a WordPress installation. The sample codes are to be implemented in index.php in a multiple-template theme (the one which has single.php, category.php, page.php, etc) or in home.php when single-template theme (the one which has only index.php) is used.

55 thoughts on “1001 WordPression Loops

  1. It would be nice if you can include the image sizes in the loop. For example the size of image is depend on the where it display. Let say the on the single.php is fullsize image, otherwize is thumbsize.

  2. Pingback: 编程猪鸡的Geek生活 » The Loop

  3. Pingback: 编程猪鸡的Geek生活 » The Loop

  4. Pingback: The HTML Artist » Blog Archive » links for 2006-01-07

  5. Thanks a lot.
    Maybe because of my poor english I haven’t found what I was looking for.
    I like to show the last 20 posts on the main page.
    the first 10 with other design (excerpt_reloaded) as the following 10 (excerpt).
    I solved it with the normal loop for the first ten and with
    $posts = get_posts('numberposts=10&offset=10');
    for the following 10. But on page 2, this is a problem: there are posts 11-20 and 11-20. Hm.
    Thanks for Your answere.

  6. Pingback: La Web A - » Configurando mltiples asides y miniblogs

  7. Great info, thanx! I would like to sort the order of posts based on a custom field – would i have to use hard-core php to achieve this?

  8. yes, the question abounds but the answer evades :- (
    it seems its one of those things that are possible in principle but would take more time – for the level of programmer that uses WordPress in stead of building their own CMS from scratch – than the sollution is worth. Just thought it may be a logical avenue of development for your CFGUI.
    Thanx for the reply.

  9. Pingback: Nate’s Blog » links for 2006-03-17

  10. I have three installations of WordPress installed.
    One in my root directory.
    One at /jamesiserman .
    One at /christianebrause .
    I have a static front page set up on the root directory installation. I would like to display 3 mini loops on it (showing the most recent entry for each blog).
    Seems simple enough, but is it possible to refer to loop in a seperate wordpress installation?

  11. James,

    You could pull the feeds of the blogs, or set up iframes. The WP forum should be able to help you further.

  12. Pingback: Malaiac attack » Blog Archive » links for 2006-04-11

  13. I’m having a play with WP and one of the things that’s giving a headache is the ability to exclude two or more categories from a loop.


    I have categories A to J. I want to display 10 posts, which do not come under category A B or C, i.e. 10 posts from D to J.

    (The 10 posts bit is less important than the exclusion bit)

    Any ideas?

  14. Typical,

    I struggle for ages, then ask… and as soon as I do I have a breakthrough! The trick is to use a counter variable:

    =10 ) :
    else: ?>

  15. Oops…. the code vanished. I’m sure it’s cleanuppable once you see the raw comment in the database (hope against hope!)

  16. Murk,

    Nope, the code was stripped out by WP–never made it to database. Good job in finding the solution, by the way.

  17. Pingback: jetstream » Blog Archive » hacking the wordpress

  18. Pingback: The HTML Artist » Blog Archive » Lingblog - January 2006

  19. Pingback: Note To Self - 1001 WordPression Loops

  20. it would be nice if you can include an example of how we can sort posts.

    i’m trying to do this, but its really hard to find informations about this subject.

    the idea is to display the posts with the default loop (posts of all categories) and add 3 links to sort the list of posts:
    sort by name, sort by date, sort by custom field.

  21. Hiya,

    it would be nice to get the excerpts running with images(thumbs), as for now only plugins can do that like the excerpts reloaded, any chance about this?

  22. Pingback: Créez votre thème Wordpress de A à Z !

  23. I am wondering if you can do a query posts to do two different things. First, can you use an include such as

    if php query_posts(‘cat1,2&showposts=10’)
    include(TEMPLATEPATH . ‘/custom.php’)

    and can you use a query posts to have certain categories feature different css styling than others so that posts categorized with “feature” would be with a bright background v. all other posts with a white background?


  24. Pingback: links for 2007-07-29 | MY Vast Right Wing Conspiracy

  25. Pingback: 09/08/07 Reperage AIA & BC at Artistik Intelligence Agency

  26. I’m interested in “Grouped by Category” function but with a category PARENT listing children categories posts.

    Really can’t find the way to do that.

  27. You could pull the feeds of the blogs, or set up iframes. The WP forum should be able to help you further.

  28. Pingback: I DoFollow but Sometimes I NoFollow… at WordPress Themes, Plugins, Blog Tips, Make Money Online >> WPthemesplugin.com

  29. Pingback: I DoFollow but Sometimes I NoFollow… | Wp Wordpress

  30. This is a great post and have kept it in my bookmarks. Will continue to read it as i’m very new to a lot of the points you mention!

    Thanks though, i’m glad some people share good stuff like this!

  31. Pingback: 12 Essential Tips to Build Your First Wordpress Theme

  32. Pingback: 建立第一個Wordpress Theme的12個關鍵

  33. Pingback: ::::..مدونة الدرس الأدبي والبحث الأكاديمي ..::: » سلسلة تصميم قوالب وورد بريس/ 01

  34. Pingback: Essential Tips to Build Your Wordpress Theme

  35. Pingback: 12 Essential Tips to Build Your First Wordpress Theme | thefirst-online

  36. Pingback: 一路飘啊,飘啊,飘…..» Blog Archive » 建立你的第一個WordPress Theme

  37. Pingback: Wordpress land - 12 Essential Tips to Build Your First Wordpress Theme

  38. Pingback: links for October 8th through December 8th | studio.pebble

  39. Pingback: WPcodex » Циклы WP (The Loop)

  40. Pingback: Votre propre thème pour votre blog « B_L_O_G de Ben, Roro, Simon

  41. Pingback: 建立你的第一個WordPress Theme

  42. Would you mind sharing what you used for formatting the code snippets shown in your posts? enscript by any chance? or any other syntax highlighting tool? Thanks for all the info, it’s incredibly useful.

  43. hello,
    i’d like to sort articles by month/year AND by category, (i.e. for example, if i have the monthly archive of may 2009, the articles should be sorted beneath headlines with the names of the categories) but if i put some code from your “grouped by category”-page into my archive.php, the sorting by month/year doesn’t function anymore. i think, because the value “monthly” of the variable (x?) does’nt get delivered from a to b (if you understand my scrubby english); i’m not the expert in php to know, where to drill the code.
    perhaps an interesting thing for you, too?

  44. Pingback: WordPress 主循环|开发基础知识|WordPress 开发| » 弗瑞斯游戏坊-DD456.com

  45. Hi,
    I’d like to create a template for showing a static page including related post: for example
    a page “Trainings” appearing in the page menu that show the content of the static page “training” AND the list of the post of category “training”.
    I guess it is a matter of multiple loop, but I don’t know how to do that.
    Can you give me some help?

Leave a Reply

Your email address will not be published. Required fields are marked *