Top Posts: Custom Post Type/Taxonomy by Comment Count


/ Published in: PHP
Save to your folder(s)

WordPress top posts: custom post type / taxonomy
Ordered by comment count


Copy this code and paste it in your HTML
  1. global $blog_id;
  2. global $post;
  3. $tax = $taxonomy = strip_tags( get_the_term_list($post->ID, 'TAXONOMY_NAME') );
  4. $termies = get_the_terms( $post->id, 'TAXONOMY_NAME' );
  5. $terms_slugs = array();
  6. foreach( $termies as $term ) {
  7. $terms_slugs[] = $term->slug; // save the slugs in an array
  8. }
  9. echo '<h2 class="widgettitle">top from <span>'. $tax .'</span></h2><ul>';
  10. $query = array(
  11. 'post_type'=> 'POST_TYPE',
  12. 'taxonomy' => 'TAXONOMY_NAME',
  13. 'term' => $term->slug,
  14. 'orderby' => 'comment_count',
  15. 'showposts' => '5'
  16. );
  17. query_posts( $query );
  18. if (have_posts()) : while (have_posts()) : the_post();
  19. echo '<div class="top-posts">';
  20. echo '<li><a href="';
  21. echo the_permalink();
  22. echo '" title="';
  23. echo the_title();
  24. echo'"><div class="comment-img">';
  25. echo the_post_thumbnail('thumbnail');
  26. echo '</div></a>';
  27. echo '<a class="title" href="';
  28. echo the_permalink();
  29. echo '" title="';
  30. echo the_title();
  31. echo '">';
  32. echo the_title();
  33. echo '</a>';
  34. echo '<div class="author">';
  35. echo '<span>'. the_time(get_option('date_format')) .' by: </span>';
  36. echo the_author_posts_link();
  37. echo '</div>';
  38. endwhile; endif;
  39. wp_reset_query();
  40. echo '</ul>';
  41. echo '</div>';

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.