Reputation: 2833
I'm having trouble with a widget that displays the most recent categories.
Code: https://ghostbin.com/paste/6cwa5 https://ghostbin.com/paste/rtnqa
It is displaying fine on the main page but when I go to a post page, it only shows that pages' categories.
Also, I have to force the widget to close with the aside
tag.
What am I doing wrong? Should I not be using the wp_get_recent_posts
function?
Why doesn't array_key_exists('after_widget', $args)
return true using twelvefifteen theme?
Upvotes: 1
Views: 57
Reputation: 531
foreach ($recent_posts as $post) {
$categories = get_the_category($post->ID);
insteadof you can use, this one belown.
because $post is a global varaiable.
Example:
$categories = get_the_category($post->ID);
foreach ($categories as $cat) {
echo $cat->cat_name;
}
Upvotes: 0
Reputation: 880
Why do you use wp_get_recents_posts
? As far as I can see from a quick look it´s not really different to get_posts()
with standard values at all.
Besides that your lines 91 and 92 could be the troublemaker.
foreach ($recent_posts as $post) {
$categories = get_the_category($post->ID);
I think, $post
is really bound to the current post you are looking at. That is no big thing on the homepage, but once you view an article, your loop-$post could be overwritten by the blogpost-$post (you know what I mean?).
Try changing those to something different than $post
, that might solve your problem.
Upvotes: 1