Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
possible duplicate of How to display related posts from same category? –  kaiser Feb 5 '12 at 17:21
add comment

1 Answer 1

up vote 1 down vote accepted

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="<?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;'); ?>
share|improve this answer
    
sorry I am noob in wordpress and PHP.If yu dont mind, could yu tell me how to put that code in my single.php?? –  Felix Feb 5 '12 at 17:01
1  
read my answer again i have added few more details (TESTED) –  Sufiyan Ghori Feb 5 '12 at 17:15
1  
sorry, replace 'ODD' with 'the' in the above code –  Sufiyan Ghori Feb 5 '12 at 17:34
1  
the error is removed from the code and now it is working perfectly fine (Tested), copy the modified code from my answer –  Sufiyan Ghori Feb 5 '12 at 17:39
1  
it means you have removed this line of code, <?php the_excerpt('Read the rest of this entry &raquo;'); ?>, add it back where it was –  Sufiyan Ghori Feb 5 '12 at 17:50
show 6 more comments

protected by Community Feb 28 '13 at 17:22

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.