使用wordpress执行if语句<! - ?php the_permalink(); ? - >

时间:2015-04-01 12:06:21

标签: php wordpress

我想在我的模板加载时创建一个条件,如果perma链接是/ xxxx / butiker则执行此操作...

如果/ xxxx / services循环这个。

或者如果/ xxxx / cafeer循环这个。

如果我渲染出<?php the_permalink(); ?>,我会得到完整的链接,但我需要一些代码来实际检查.com / xxx / THIS部分。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

使用PHP explode()功能分割URL:

$link = get_permalink();
$temp = explode("/",$link);
print_r($temp);

get_permalink()函数返回URL,print_r打印数组。如果条件如此,请获取您要签到的部分

例如:

Array ( [0] => www.xyz.com
        [1] => xxx
        [2] => services
      ) 

if($temp[2] == "services"){
     //your loop for services ,cafeer etc..
}
相关问题