• Hi, I have to use JohnPope’s solution from here
    https://www.ads-software.com/support/topic/155342
    because I can add excerpts and thumbnails to that list, but the problem is that this code below just show other posts from the first category this post is found in. I need it changed to check all categories that current post is in and display the latest post found in any of these categories. Anybody know how to do that ?

    <?php
    global $post;
    $categories = get_the_category();
    $category = $categories[0];
    $cat_ID = $category->cat_ID;
    $myposts = get_posts("numberposts=8&category=$cat_ID");
    ?>
    <?php foreach($myposts as $post) :?>
    "><?php the_title(); ?>
    <?php the_thumb(); ?><?php the_excerpt(__('Read More'));?> " href="<?php the_permalink(); ?>">

    <?php endforeach; ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Not sure what the_thumb is, but will throw this at you for your use. Also this will work in a [The Loop|Loop]].

    <?php
    global $post;
    $cat_ID=array();
    $categories = get_the_category(); //get all categories for this post
      foreach($categories as $category) {
        array_push($cat_ID,$category->cat_ID);
      }
      $args = array(
      'orderby' => 'date',
      'order' => 'DESC',
    	'post_type' => 'post',
    	'numberposts' => 8,
    	'post__not_in' => array($post->ID),
    	'category__in' => $cat_ID
      ); // post__not_in will exclude the post we are displaying
        $cat_posts = get_posts($args);
        $out='';
          foreach($cat_posts as $cat_post) {
              $out .= '<li>';
              $out .=  '<a href="'.get_permalink($cat_post->ID).'" title="'.wptexturize($cat_post->post_title).'">'.wptexturize($cat_post->post_title).'</a></li>';
          }
        $out = '<ul class="cat_post">' . $out . '</ul>';
        echo $out;
    ?>

    MichaelH thank you so much for this.

    Do you know how I might be able to exclude some categories, for example categories ID:1,2,3,and 4?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Recent posts from all categories that current post is. How?’ is closed to new replies.