-1

I want to make a condition when my template loads, if the perma link is /xxxx/butiker then do this...

And if /xxxx/services loop this.

or if /xxxx/cafeer loop this.

If I render out <?php the_permalink(); ?> I get the full link, but I need some code to actually just check the .com/xxx/THIS part. Could someone assist?

1 Answers1

1

Split the URL using PHPs explode() function:

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

The get_permalink() function returns the URL, and print_r prints the array. Get your part which you want to check in if condition like;

For example:

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

if($temp[2] == "services"){
     //your loop for services ,cafeer etc..
}
Martijn
  • 11,964
  • 12
  • 50
  • 96
K'val
  • 11
  • 4
  • This is a good answer and explanation so +1 but could be better I think if using `basename()` or `end()` rather than `temp[2]` as the url might have more parts to it. http://stackoverflow.com/questions/7395049/get-last-part-of-url-php – McNab Apr 01 '15 at 13:42