I’m attempting to create a second nav menu on my wordpress site.
I want this to show links to all posts within the current category only.
I’ve been experimenting with the get_posts function but am struggling to find how to dynamically select the current category. i.e. what to place in here category=x
Any help is greatly appreciated
Here is my template code I have been using
<ul id="catnav">
<?php
global $post;
$myposts = get_posts('numberposts=5&category=1');
foreach($myposts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
Finally solved it with this code from here: http://www.snilesh.com/resources/wordpress/wordpress-recent-posts-from-current-same-category/
Modified it to include current page and list ascending
It worked for me!
So I found this bit of code which works great in showing all posts in the current category.
But I have several categories I wish to exclude.
Some posts exist in two categories I want to exclude showing the post in categories 8,9 and 11.
Any ideas?
I think it is better to get posts from category id instead of category name
so that you can write an if else condition and you can exclude the posts which are having the id as 8,9,11