That’s kind of a mouthful, eh?
With all the talk of organizations using WordPress as their website CMS, it’s pretty surprising some features aren’t yet part of the core code or at least surprising that some hacks aren’t more distributed. A very basic feature I know every news site would want is the ability to post multiple headline stacks on one page and control how many headlines each stack displays.
I’m currently in the process of transforming a very static agency intranet homepage into something more vibrant and news-powered using WordPress and I spent an hour searching for the most fool-proof, direct way to accomplish the display of multiple categories on one page. I thought I’d pass along the best solution I’ve found.
The crux of the problem is that using multiple loops on a single page seems to affect the way each loop displays, and not in a good way. No matter how I tried to reset or rewind a loop, it just caused problems for itself, another loop or the entire page. I used WP Modder’s solution and it worked like a charm.
His usage was slightly different than mine. His setup was:
1) Pull the first few headlines from a particular category and display them in a unique way
2) Then display the rest of the headlines normally without duplicating headlines from the previously displayed category
My setup was:
1) Every post is assigned ONE category
2) Every category will display X number of headlines on the front page and that number will vary depending on the category
To accomplish that, you replace this in every instance of your loop:
1 | <?php while ( have_posts() ) : the_post() ?> |
… with this:
1 2 | <?php $my_query = new WP_Query('category_name=My Badass Category&showposts=3'); while ($my_query->have_posts()) : $my_query->the_post(); ?> |
… obviously replacing the category name and the number of posts to show. Using the same query name multiple times for this purpose may not be kosher, but it works and my page isn’t broken, so I’m sticking with it. Of course, most news sites would assign multiple categories to a post, but, uh, that’s your problem.





