使用wordpress<;?执行if语句;?php the_permink()>;


Doing an if statement with wordpress <?php the_permalink(); ?>

我想在加载模板时设置一个条件,如果perma链接是/xxxxx/butiker,那么就这样做。。。

如果/xxxx/services循环这个。

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

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

使用PHPs 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..
}