WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Displaying Category without linked text (9 posts)

  1. jamiedustuk
    Member
    Posted 4 years ago #

    I can use <?php the_category(); ?> to show the category im in, but I want to be able to display the current category name without it appearing as a list and without the link i.e.

    Is there a line of code i can use to simply output the current category name, then I can do what I like with this...

    thanks.

  2. Oren Yomtov
    Member
    Posted 4 years ago #

    get_the_category()

  3. jamiedustuk
    Member
    Posted 4 years ago #

    using <?php get_the_category(); ?> doesnt seem to do anything.

    anyone else? ... i just want to display as plain text the name of the category im in, for example, i want to say: Currently viewing: 'category name'

    thanks again

  4. t31os
    Member
    Posted 4 years ago #

    <?php echo get_the_category(); ?>

  5. jamiedustuk
    Member
    Posted 4 years ago #

    that doesnt work either, i just get the words: Array

  6. Oren Yomtov
    Member
    Posted 4 years ago #

    thats because the post has more then one category then it returns an array.
    try
    `<?php
    $cats=get_the_category();
    if( is_array($cats) )
    print_r($cats);
    else
    echo $cats;
    ?>

  7. Oren Yomtov
    Member
    Posted 4 years ago #

    thats because the post has more then one category then it returns an array.
    try

    <?php
    $cats=get_the_category();
    if( is_array($cats) )
    	print_r($cats);
    else
    	echo $cats;
    ?>
  8. jamiedustuk
    Member
    Posted 4 years ago #

    the post is only in 1 category and when i try that code i get

    Array ( [0] => stdClass Object ( [term_id] => 11 [name] => Out and about [slug] => out-and-about [term_group] => 0 [term_taxonomy_id] => 11 [taxonomy] => category [description] => [parent] => 0 [count] => 1 [object_id] => 25 [cat_ID] => 11 [category_count] => 1 [category_description] => [cat_name] => Out and about [category_nicename] => out-and-about [category_parent] => 0 ) )

  9. Mark / t31os
    Moderator
    Posted 4 years ago #

    <p><?php single_cat_title('Category:'); ?></p>

    or

    <?php
    $cats=get_the_category();
    echo $cats[0]->cat_name;
    ?>

    Info:
    http://codex.wordpress.org/Template_Tags/single_cat_title
    http://codex.wordpress.org/Template_Tags/get_the_category

  10. jamiedustuk
    Member
    Posted 4 years ago #

    just the ticket... thanks

Topic Closed

This topic has been closed to new replies.

About this Topic