WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. stanlaurent
    Member
    Posted 4 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 !

    http://wordpress.org/extend/plugins/list-category-posts/

  2. MichaelH
    Member
    Posted 4 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.

    <?php
      $categories = get_the_category();
      if ($categories) {
        foreach ($categories as $category) {
          $cat = $category->cat_ID;
          $args=array(
            'cat' => $cat,
            'post__not_in' => array($post->ID),
            'posts_per_page'=>5,
            'caller_get_posts'=>1
          );
          $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>
             <?php
            endwhile;
          } //if ($my_query)
        } //foreach ($categories
      } //if ($categories)
      wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. jonnyw
    Member
    Posted 4 years ago #

    That's really useful, Michael, thank you.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic