List category posts
See posts list from current categorie (3 posts)

  1. stanlaurent
    Posted 5 years ago #

    I'd like to show a list of posts from the post's category without telling to Catlist the ID or the NAME of the category
    Like : [catlist current]
    Thanks !


  2. MichaelH
    Posted 5 years ago #

    Might consider using something like this in your theme template that displays posts--for each category of that post i.e. related, display 5 posts in that category, excluding the single post.

      $categories = get_the_category();
      if ($categories) {
        foreach ($categories as $category) {
          $cat = $category->cat_ID;
            'cat' => $cat,
            'post__not_in' => array($post->ID),
          $my_query = null;
          $my_query = new WP_Query($args);
          if( $my_query->have_posts() ) {
            echo '<h2>More Posts from '. $category->category_description . '</h2>';
            while ($my_query->have_posts()) : $my_query->the_post(); ?>
              <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
          } //if ($my_query)
        } //foreach ($categories
      } //if ($categories)
      wp_reset_query();  // Restore global post data stomped by the_post().
  3. jonnyw
    Posted 5 years ago #

    That's really useful, Michael, thank you.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • List category posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic