jamiedustuk
Member
Posted 3 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.
jamiedustuk
Member
Posted 3 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
<?php echo get_the_category(); ?>
jamiedustuk
Member
Posted 3 years ago #
that doesnt work either, i just get the words: Array
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;
?>
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;
?>
jamiedustuk
Member
Posted 3 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 ) )
<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
jamiedustuk
Member
Posted 3 years ago #
just the ticket... thanks