Advertisement
deepbevel

posts of most recent tag in category

Jun 26th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php/*
  2. this code outputs a linked list of all posts in a specific category which share the same tag as the most recent post, as well as a link to that tag's archive
  3. */?>
  4.  
  5. <?php
  6. global $post;
  7. query_posts ('cat=1 &posts_per_page=10'); ?>
  8. <?php if ( have_posts() ) : ?>
  9. <?php while (have_posts()) : the_post(); ?>
  10.  
  11. <h4>
  12. <?php
  13. the_tags( __( ' ',
  14. ' ' ), ', ', ''); ?> </p><?php
  15. $posttags = get_the_tags($post->ID);?>
  16. </h4>
  17.  
  18. <ul>
  19. <?php
  20. $tags = wp_get_post_tags($post->ID);
  21. if ($tags) {
  22. echo '';
  23. $first_tag = $tags[0]->term_id;
  24. $args=array(
  25. 'tag__in' => array($first_tag),
  26. 'showposts'=>-0,
  27. 'caller_get_posts'=>1,
  28. 'order' => 'ASC'
  29. );?>
  30.  
  31. <?php
  32. $my_query = new WP_Query($args);
  33.  
  34. if( $my_query->have_posts() ) {
  35. while ($my_query->have_posts()) : $my_query->the_post(); ?>
  36. <p style="padding: 1px; margin: 0;">
  37. <a>">
  38. <?php the_title(); ?> </a></p>
  39. <?php endwhile;}}?>
  40.  
  41. <!-- /html code -->
  42. <?php endwhile; ?>
  43. <?php else : ?>
  44. <!-- html code if nothing found -->
  45. <?php endif; ?>
  46. <?php wp_reset_query();?>
  47.  
  48. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement