WordPress.org

Ready to get started?Download WordPress

Forums

Showing Categories in recent posts widget (1 post)

  1. jylppy81
    Member
    Posted 9 months ago #

    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?

Reply

You must log in to post.

About this Topic