使用Wordpress插件根据自定义分类法对自定义帖子类型进行排序。结果将在帖子类型的存档页面上返回。排序工作得很好但尝试显示具有多个分类的项目的标题内容:
<?php if(strstr($_SERVER['REQUEST_URI'], "level/invigorating")) { ?>
<h3>These poses are invigorating:</h3>
<?php } ?>
<?php if(strstr($_SERVER['REQUEST_URI'], "level/invigorating/position/seated")) { ?>
<h3>These poses are invigorating and seated:</h3>
<p>For positions of this nature please take care of your sacrum.</p>
<?php } ?>
<?php if(strstr($_SERVER['REQUEST_URI'], "position/seated")) { ?>
<h3>These poses are seated:</h3>
<?php } ?>
"level/invigorating/position/seated"
返回三个h3
,因为所有if
都返回true。
我的PHP技巧很糟糕,试图理解手册就像是盯着夜空。
如何编写,每页只能返回一个值?
也许this screenshot有帮助。
答案 0 :(得分:1)
我相信你要做的就是这个......
<?php if(strstr($_SERVER['REQUEST_URI'], "level/invigorating/position/seated")) { ?>
<h3>These poses are invigorating and seated:</h3>
<p>For positions of this nature please take care of your sacrum.</p>
<?php } elseif(strstr($_SERVER['REQUEST_URI'], "level/invigorating")) { ?>
<h3>These poses are invigorating:</h3>
<?php } elseif(strstr($_SERVER['REQUEST_URI'], "position/seated")) { ?>
<h3>These poses are seated:</h3>
<?php } ?>