if homepage show...
Permalink 1 user found helpful
Is there a script that would display an item on the homepage only?
if (homepage) echo this;
if (homepage) echo this;
Easiest would probably be..
$p = Page::getCurrentPage(); if($p instanceof Page && !$p->isError() && $p->getCollectionID() == HOME_CID){ //do stuff }
$p = Page::getCurrentPage(); if(!$p->isError() && $p->getCollectionID() == HOME_CID){ //do stuff }
it has to be an instance of Page, thanks to the line above it :P
that is true, though the class document comments for the particular method don't hint at the return type at all(be it object or otherwise) so I feel that for learning purposes while you can check if something is error you always want to check to see if it is an instance of the class you are expecting before calling a class instance method on it. you could also use is_callable or method_exists or whatever, not sure why you even felt the need to comment.
-Scott
-Scott
So assuming you can't trust the api(not saying you can't) but if you want something that should theoretically always work you want to dequalify from left to right..
$p = Page::getCurrentPage(); if(is_object($p) && $p instanceof Page && !$p->isError() && $p->getCollectionID() == HOME_CID){ //this clear enough? }
Sweet!
This helped me not have to make a single page for the homepage. Very nice. How could you add multiple pages?
This helped me not have to make a single page for the homepage. Very nice. How could you add multiple pages?
Thanks for this - perfect!