Showing Categories in recent posts widget
I’m hosting a wordpress site for a sports club where we put up match reports and other news and they are categorised according to the teams.
Now, I’m otherwise happy with the default recent posts widget, but I’d love to have the category (the team name) showing by the post. Each team have their own categories under which we have sub-categories (e.g. /men/news, /women/matchreports) I tried adding the following in the default-widgets.php:
<ul> <?php while ($r->have_posts()) : $r->the_post(); ?> <li> //next line added by me <?php echo get_category_parents( get_the_category (), false, ' » '); ?> <br /> <a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li> <?php endwhile; ?> </ul>
This causes all the posts showing “Uncategorized” as their parent category. Any ideas how I could get either just the top level category or the entire category path displayed in the widget?
- The topic ‘Showing Categories in recent posts widget’ is closed to new replies.