使用 strstr 基于多个 url 值的内容可见性


Content visibility based on multiple url values with strstr?

使用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技能很糟糕,试图理解手册就像盯着夜空。

如何写它,以便每页只能返回一个值?

也许这张截图有所帮助。

使用漂亮的分类过滤器。

我相信

你想做的是这个......

<?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 } ?>