WordPress.org

Ready to get started?Download WordPress

Forums

Remove link to category archive in posts, but keep the text (5 posts)

  1. richardhenry
    Member
    Posted 7 years ago #

    I'm currently developing a theme for WordPress, and want to be able to show on posts 'This was posted on DATE in CATEGORY.'

    The CATEGORY part is the issue here.

    I can display the current category using the code:

    <?php the_category(', ') ?>

    ...but this not only displays this category, but makes the text linkable so the viewer can see more posts in the same category.

    Is there any way to show just plain text the category name, without having this as linkable text?

  2. moshu
    Member
    Posted 7 years ago #

    It seems you missed this while searching for an answer:
    http://codex.wordpress.org/Template_Tags/get_the_category

  3. richardhenry
    Member
    Posted 7 years ago #

    So I did, very sorry. Thanks for your reply!

  4. richardhenry
    Member
    Posted 7 years ago #

    P.S. For anyone who can't be bothered reading all that, simply insert:

    <?php foreach((get_the_category()) as $cat) { echo $cat->cat_name . ' '; } ?>

    ...anywhere in The Loop to display the category of the current post.

  5. godofcomics
    Member
    Posted 6 years ago #

    I needed the Category ID only, in text form [non-link]. So, if that is what you are also looking for, here is the code I found and tested: [it works].

    <?php foreach((get_the_category()) as $cat) { echo $cat->cat_ID . ' '; } ?>

    It displays only the cat id (number) instead of the name.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags