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
https://forums.phpfreaks.com/topic/261086-hide-a-div-based-on-url/
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!

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.