[英]Wordpress category query not working
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 );
所以我定义了
$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. 看一下
single_cat_title()
的手册页 ,您会看到它带有两个参数。 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
). 第二个在这里很重要-它定义您是要回显类别(如果为
true
)还是要返回类别(如果为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
. 在当前代码中,您只是在呼应标题,并且
$thecat
被设置为null
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.