General Community > Scripting Help

Content on Home Page Only

(1/1)

robertwatcher:
I have added a div with content to the top of my forum page in index.template.php. It is working fine - but I only want it to show on the first index page.  It now consists of a twitter feed and I will add a couple of other components or a display of latest posts into the div as well (http://dslrphotoforum.com/)

I figured there may be some preset variables that would allow me to do the logic for that in php. I found this on the web with a serach for what I wanted to do - "if ($context['current_action'] == ''){ }" - but it didn't work.

If there an SMF variable I can use in my if logic that would separate out the index page?

Thanks

robertwatcher:
I couldn't find anything further - so just decided to go with

if (empty($_SERVER['QUERY_STRING'])) {

}

for now.

gazzerman:
I was looking for the same thing as I was too lazy to test some code :)

I think what you or anyone else is looking for is this:-

if($_SERVER['REQUEST_URI'] == "/"){

//some code goes here

}


This will return the current page you are on, if its the root page it will return a "/", simply compare it to that, or "/index.php" etc... this should make sure your homepage content always shows. however it will not work if there is also a query string e.g. /?var=something

To resolve that you could always do a:-

$variable1 = str_replace("?" . $_SERVER['QUERY_STRING'], "", $_SERVER['REQUEST_URI']);

if($variable1  == "/"){

//some code goes here

}

Problem solved :)

Navigation

[0] Message Index

Go to full version