I want to get the category from the current archive page with
<?php single_cat_title( '', true ); ?>
So i defined $thecat = single_cat_title( '', true );
and now I am trying only to echo something if the category isn't the current one.
<?php if($thecat !== "Stuff") { echo'<li><a href="/stuff"> Stuff</a></li>';}?>
But it is not working.. what is wrong here?
You're almost there.
Have a look at the manual page for single_cat_title()
, you'll see that it takes two parameters. The first is a prefix to use in the return; the second is the important one here - it defines whether you want the category to be echoed out (if true
), or returned (if false
). So all you need to do is swap:
$thecat = single_cat_title( '', true );
to:
$thecat = single_cat_title( '', false );
In your current code, you're just echoing the title, and $thecat
is being set to null
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.