Multiple Loops in Wordpress
I wanted to run the wordpress loop on my php page more than once, & I don’t know if I’m the only person, but I found the offical multiple look example hard to swallow.
Google found is nima’s how to which was useful, but I wanted to take it further; the problem was I wanted a function.
This is what I came up with:
require(’path_to_wordpress/wp-blog-header.php’);
?>
<?php
function show_posts_from_cat($MYCAT){
?>
<ul>
<?php if (have_posts()) : ?>
<?php $my_query = new WP_Query(”category_name=$MYCAT”); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li>

Tags: