Jump to content

Hide a div based on url


Thomshaw

Recommended Posts

Hi all,

 

Relitively new to PHP but am trying to code a site that dynamically creates urls using Joomla CMS. Basically I'd like a div to show on pages' url starts /component/.... but hide it if not. The urls of the pages on which the div is to be hidden start /index.php?.

 

I've tried

 


<?php 

		   if (strpos($_SERVER['REQUEST_URI'], 'component') > 0) {
		   echo '<div id=\"stuffdiv\">stuff</script></div>';}

	?>

 

only issue is... its always fasle hence the div never shows. If i replace > with >= its always true, and appears on all pages, even those not containing 'component'...

 

Can someone tell me if this should work or if Im being really stupid?

 

Thanks in advance! Tom

Link to comment
Share on other sites

if (strpos($_SERVER['REQUEST_URI'], 'component') !== false) {
    echo '<div id="stuffdiv">stuff</script></div>'; // You do not need to escape the double-quotes unless you create the string using double quotes.
}

Link to comment
Share on other sites

Amazing CPD thanks so much, worked with a little jiggery pokery

 

 

<?php 

		   if (strpos($_SERVER['REQUEST_URI'], 'foo') == false) {
    		   echo '<div id="stuffdiv">stuff</div>';}

	?>

 

where foo appears in the url of the page on which the div should be hidden

 

Again, can't thank you enough!

Link to comment
Share on other sites

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.