Jump to content

[SOLVED] Help with extracting a specific part of an URL


bronzemonkey

Recommended Posts

If I have links in these formats...

 

1) http://www.somewebsite.com/IWANTTHIS/

2) http://www.somewebsite.com/IWANTTHIS/this-is-unwanted-and-variable/

 

...and I'd like to extract the IWANTTHIS part (which is not constant) from the permalinks, how do I go about doing this?

 

I'm trying to find a way to achieve context sensitive menus in wordpress and this seems to be the only way to access the page-slug of pages and posts. Thanks for any help.

Thanks, I ended up using the following (in wordpress):

 

<?php
$url = get_permalink('', false); // get the permalink
$spliturl = explode("/", $url); // break down the permalink
$pageID = $spliturl[3]; // select the page slug
?>

<body id="body_<?php echo $pageID; ?>">

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.