• Hello,

    Is there a way to make it happen so that when a user arrives at a post on a blog from a direct link to that post WordPress also displays all other posts from the same category that post is in?

    So for example a user goes a Google search on peacocks and one of my posts is displayed in Google and a user clicks on it. That post is from a category called birds and when the user arrives at that post WordPress also displays all the other posts from the birds category.

    Can it be done?

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter jf80

    (@jf80)

    Thank you.

    Do you know if it is possible to display the actual posts rather than the titles?

    I don’t know. But seriously? Wouldn’t that be a bit too much info on one page?

    For use in single.php, display all posts for each catetory assigned to the single post:

    <?php
    if ( is_single() ) {
      $categories = get_the_category();
      if ($categories) {
        foreach ($categories as $category) {
          // echo "<pre>"; print_r($category); echo "</pre>";
          $cat = $category->cat_ID;
          $args=array(
            'cat' => $cat,
            'post__not_in' => array($post->ID),
            'posts_per_page'=>-1,
            '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
              the_content();
            endwhile;
          } //if ($my_query)
        } //foreach ($categories
      } //if ($categories)
      wp_reset_query();  // Restore global post data stomped by the_post().
    } //if (is_single())
    ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Automatically show all other posts from same category?’ is closed to new replies.