ZenphotoCMS Forum
Function to detect home page? - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: Themes (https://forum.zenphoto.org/forum-5.html)
+--- Thread: Function to detect home page? (/thread-7800.html)



Function to detect home page? - amucklow - 03-11-2010

I've checked the function reference, but can't find anything that lets me write a conditional statement in e.g. header.php as follows:

if (is_home_page()) { // do something } else { // do something different }
I know I can create a separate index.php file, but it would be neater to have e.g. a single header file that loads e.g. different scripts or styles depending on the context.

Thanks




Function to detect home page? - acrylian - 03-11-2010

Well, each theme has a index.php file always... You can use the global variable $_zp_gallery_page to check for the index.php theme page.

In general you have to use the object model to differ album, image or Zenpage page/news contexts. Zenpage items however have is_Pages() and is_News() for hte pages.php and news.php pages.

See the user guide about a tutorial for that. I assume you have read the theming tutorial already.




Function to detect home page? - amucklow - 03-11-2010

Thanks acrylian.

Also - is there any way to distinguish between index.php and a separate home page like index-gallery.php?

I have index.php for my 'splash' page and index-gallery.php for my album overview - but $_zp_gallery_page equals index.php for both.

I could get into finding a string in the URL but that's a bit messier.




Function to detect home page? - micheall - 04-11-2010

I assume you've set the gallery index page via options to be the index-gallery.php?




Function to detect home page? - amucklow - 10-11-2010

For the record, here's my solution.

To recap, I have a home/splash page (index.php) distinct from my gallery index page (gallery-index.php) - and I want them to have different body classes, so that the splash gets a background image, and the gallery index doesn't.

In Zenphoto, the $_zp_gallery_page global resolves to 'index.php' on both pages.

So:

`
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

$gallery = strpos(curPageURL(), 'gallery');

?>




Function to detect home page? - acrylian - 10-11-2010

I see you call gallery-index.php using page/gallery-index. I assumed you have called it within index.php?

In this case it is a normal custom page and should like like one. $_zp_gallery_page should really return gallery-index.php. It does this with all custom pages (archive.php,contact.php,gallery.php of the Zenpage theme) I just tested to be sure.
You can also test manually for $_ GET['p'].

Btw, you are running on the older 1.3 release. The 1.3.1.x release were security bug fix releases and we strongly recommend to upgrade.

PS: Nice site. You should submit to the showcase. Small suggestion: I would implement mousewheel support for the thumbs (I see it is loaded actually but in Firefox & Safari 4.1.2 it does not work):




Function to detect home page? - amucklow - 10-11-2010

Thanks.

$_zp_gallery_page returns 'index.php' on both pages. However $_GET['p'] is useful. So now I have in header.php:

`




Function to detect home page? - acrylian - 11-11-2010

Well, then I guess you are doing something different. If the page is named "gallery-index.php" why are you able to check for "gallery"?