Seb*_*bie 5 php url wordpress if-statement path
是否有 if 语句允许我检查 URL 是否包含特定路径?
在我的特定情况下(使用 wordpress),我试图检查 URL 是否包含/store/ https://www.website.com.au/store/brand/ 所以在该路径之后可能会有一些东西......
感谢您的帮助!
小智 6
我建议使用 WordPress 函数,如 is_singular、is_tax 等。
\n\nfunction get_current_url()\n{\n $pageURL = \'http\';\n if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {\n $pageURL .= "s";\n }\n $pageURL .= "://";\n if ($_SERVER["SERVER_PORT"] != "\xdb\xb8\xdb\xb0") {\n $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];\n } else {\n $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];\n }\n return $pageURL;\n}\n\n$url = get_current_url();\n\nif (strpos($url, \'/store/\') !== false) {\n echo \'found\';\n}else{\n echo \'not found\';\n}\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
7856 次 |
最近记录: |