Jump to content

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


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; ?>">

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.