Want to show related WordPress posts within a category or tag group on a post?
Basically a loop within a loop = 2 queries.
Example usage: Say you write a post about a topic and want to display all the posts within a particular category and display then on the web page. Sort of a summary of posts. The WordPress Optimization Guide post displays related posts within a post as a working example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // if it is a single post // use number of post slug if ( is_single('101') ) { // create a new query // can use category or tag // example of both $my_query = new WP_Query('cat=202&tag=seo'); // start while loop while ($my_query->have_posts()) : $my_query->the_post(); // place loop content here .... // end while loop endwhile; // close the if statement } |
Here is the skeleton code:
The simplest of examples, more can be found in reference links:
Any other methods or recommended plugins, let us know.
I think your article was really a great start to a potential series of articles about this topic. Most users pretend to know what they are writing about when it comes to this area and most of the time, hardly anyone actually get it. You seem to grasp it though, so I think you should run with it. Thank you!