Php 通过permalink获取帖子的类别
我有一篇文章分为两类(a类,B类)。当我访问帖子时,例如“/category-b/post name”,获取页面当前类别的最佳方式是什么?在这种情况下,我希望收到“b类”Php 通过permalink获取帖子的类别,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我有一篇文章分为两类(a类,B类)。当我访问帖子时,例如“/category-b/post name”,获取页面当前类别的最佳方式是什么?在这种情况下,我希望收到“b类” 谢谢,您可以使用parse_url从url获取路径,然后使用explode将其拆分为段: $uri_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $uri_segments = explode('/', $uri_path); echo $uri_segme
谢谢,您可以使用
parse_url
从url获取路径,然后使用explode
将其拆分为段:
$uri_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri_segments = explode('/', $uri_path);
echo $uri_segments[1]; // for www.example.com/category-b/post-name you will get 'category-b'.