In my gallery site i want to show other pictures under the current picture (in single post). I seen more codes but it i asks to specify the category, but i dont want want specify the category manually in the code I want the code itself to get the category ID or name.It would be much easier for me if i get full posts instead of post title so that I can display it as in home and category

3 s
3

The question has already been asked and the answer has been posted too,

How to display related posts from same category?

Add this code inside your single.php after a loop wherever you want to show related post,

<?php

$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 5, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
 <ul> 
        <li>
        <a href="https://wordpress.stackexchange.com/questions/41272/<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
            <?php the_content('Read the rest of this entry &raquo;'); ?>
        </li>
    </ul>   
<?php }
wp_reset_postdata(); ?>

It will display related post from the same category with the post excerpt and title ,
however if want this code to display just the title of related post then remove this line,

<?php the_content('Read the rest of this entry &raquo;'); ?>

Leave a Reply

Your email address will not be published. Required fields are marked *