3
votes

I'm planning on making a template page for a Wordpress theme that will load 5 separate "modules" within the content part of the page. These modules are intended to each show the latest 4 posts of different categories (to work similarly like this).

What is the best way to approach this for the loops?

As page.php will call the while have_posts loop to execute the template, the template php itself will have the five modules. Normally I would do a while have_posts to query, but doing this five times within one page inside a while have_posts seems like nothing but trouble.

Is there a more convenient way to achieve this?

1

1 Answers

2
votes

Yes, the preferred way to do multiple loops is to create a new WP_Query object for each loop. You know the have_posts function and so on that you use for loops now? They're just helpers. Those methods exist inside the WP_Query object too, so that way you can have one loop for each object you create.

Read about that here: http://codex.wordpress.org/Class_Reference/WP_Query

get_posts also comes to mind. But you wouldn't be able to build real Wordpress loops using that function, because it just returns the posts in a numeric array.