I’m trying to insert what might be described as a mini-sidebar on my some of my themes’ pages. I am also using the regular sidebar.
I’ve got this working using custom page templates and then wp-query for each one to list the posts relating to that page using their category.
However, it would be easier to simply be able to use the category itself without needing a custom page template.
So ideally I want to interrupt the loop that is taking place on content.php and insert a mini loop that calls content from a particular page or category and drops it into a div. Then I want to carry on with the main loop as called for that category.
The trouble is when I do this my mini-loop is repeated for as many posts as there are in the main loop.
This is the code I’m using:
<?php
// The Query
$the_query = new WP_Query( 'cat=4');
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
echo "does this repeat";
}
/* Restore original Post Data */
wp_reset_postdata();
?>
Then I want to continue to call the posts as normal. But the above query loops for as many posts are in the main query.
Thanks