Member
Member
amucklow   2010-11-03, 20:14
#1
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
Administrator
Administrator
acrylian   2010-11-03, 20:20
#2
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.
Member
Member
amucklow   2010-11-03, 21:38
#3
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.
Member
Member
micheall   2010-11-04, 07:27
#4
I assume you've set the gallery index page via options to be the index-gallery.php?
Member
Member
amucklow   2010-11-10, 19:45
#5
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');

?>
<body <?php if ($_zp_gallery_page == 'index.php' && $gallery === false) { echo 'class="home"'; } ?>>
`
If `$_zp_gallery_page` is 'index.php' AND the page URL does not have 'gallery' in it, add the class 'home' to the body element.

Note that if you have called your gallery index page something else like 'overview', you will have to substitute 'gallery' for 'overview'.

If anyone has a more elegant solution I'd be keen to hear it. What we really need is a pair of functions like in Wordpress: `is_home()` and `is_front_page()`. ;-)

Here it is working: http://jaslehalphotography.co.uk/
Administrator
Administrator
acrylian   2010-11-10, 20:12
#6
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):
Member
Member
amucklow   2010-11-10, 21:28
#7
Thanks.

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

`
<body <?php if ($_zp_gallery_page == 'index.php' && $_GET['p'] != 'gallery') { echo 'class="home"'; } ?>>
`
which is neater.

I will update - and submit to showcase. Thanks for heads up on mousewheel - it will be related to the jQuery version I expect.
Administrator
Administrator
acrylian   2010-11-11, 10:52
#8
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"?
  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.