multiple loops > php help
-
Hi
I need 3 separate loops on my category pages – one that shows the latest 5 posts from the category, another that shows the 5 before that, and then another that shows the 12 before that. I have 42 categories.
Currently, for each section, I am running through all 42 categories in one huge if statement. That means 3 huge if statements for each category page. I find it hard to believe that I am doing it in the most efficient way! Any help would be greatly appreciated :)
Example of the current code:
<?php if (is_category('1')) : ?><?php $recent = new WP_Query("cat=1&showposts=12&offset=10"); while($recent->have_posts()) : $recent->the_post(); ?>
- "><?php the_title(); ?>
<?php endwhile; ?>
<?php elseif (is_category('2')) : ?>
<?php $recent = new WP_Query("cat=2&showposts=12&offset=10"); while($recent->have_posts()) : $recent->the_post(); ?>
- "><?php the_title(); ?>
<?php endwhile; ?>
...
<?php elseif (is_category('42')) : ?>
<?php $recent = new WP_Query("cat=42&showposts=12&offset=10"); while($recent->have_posts()) : $recent->the_post(); ?>
- "><?php the_title(); ?>
<?php endwhile; ?>
<?php endif; ?>
-
Hi there, I’m afraid you’re at the wrong place. https://en.forums.wordpress.com/topic/please-read-me-first-before-posting?replies=1
You want to be here http://wordpress.org/support
-
-
- The topic ‘multiple loops > php help’ is closed to new replies.