Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

stiwdio on "Display Posts in same category"

$
0
0

Hi

Have a bit of a brainteaser, wonder if anyone smart enough can help me out; I've got a single post page that displays a singe post :-)

But underneath I wish to display posts in the same category, I have the code below, which works, HOWEVER :-) I want it to exclude the current post AND exclude duplicates of posts, as for example I want to be able to tag a post in multiple categories but other posts might be in multiple categories also, so it might bring in multiple copies of the same post;

Does that make sense? Hopefully it does

Thanks for any help

<?php
	global $post;
	$categories = get_the_category();
	foreach ($categories as $category) :?>
		<?php
			$posts = get_posts('numberposts=3&category='. $category->term_id);
			foreach($posts as $post) : ?>

			<li>
				<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
			</li>

		<?php endforeach; ?>
<?php endforeach; ?>

Viewing all articles
Browse latest Browse all 8245

Trending Articles