• Resolved tgwpqd

    (@tgwpqd)


    Hi,
    In the single.php, I want to show the recent posts in the same category (each post has single category in my wordpress) as the post story. Here is my code:

    <h4>Recent stories in the <?php the_category(', ') ?> category</h4>
    	<ul>
    	<?php
    	global $post;
    	$category_posts = get_posts('numberposts=5&offset=1&category_name=<?php the_category(', ') ?>');
    	foreach($category_posts as $post) :
    	?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	<?php endforeach; ?>
    </ul>

    However, the list that I got is the first category in my wordpress database, not the same category as show in my <h4>. Can anyone tell my what I did wrong in my code?

Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘list links in same category (something wrong)’ is closed to new replies.