如何使$ _GET函数与重写的URL一起工作?

时间:2016-01-15 21:24:14

标签: php css wordpress printf author

我尝试使用

$_GET['glossary']
在wordpress functions.php中的

功能隐藏了以下域的特定帖子的某些路径

https://sampledomain.com?glossary=extrathing

以下是此

的完整代码
if ($_GET['glossary']){
         printf('<style>.author-box{display:none;}</style>');
}

它完美无缺,并隐藏了特定帖子的作者框。

然而,当我在wordpress中激活固定链接时,将URL更改为

https://sampledomain.com/glossary/extrathing/

$ _GET的上述功能不再有效,请问有什么建议吗?

2 个答案:

答案 0 :(得分:0)

您可以更改条件以检查uri

if ($_GET['glossary'] || $_SERVER['REQUEST_URI'] == '/glossary/extrathing/'){
         printf('<style>.author-box{display:none;}</style>');
}

答案 1 :(得分:0)

对重写的URL使用get_query_var('glossary'),

相关问题