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;

 
aghouseh replied on at Permalink Reply
aghouseh
Easiest would probably be..
if ($c->getCollectionID == 1){
   echo 'homepage content'; // whatever you want here
}
ScottC replied on at Permalink Reply
ScottC
$p = Page::getCurrentPage();
if($p instanceof Page && !$p->isError() && $p->getCollectionID() == HOME_CID){
//do stuff
}
Mnkras replied on at Permalink Reply
Mnkras
$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
ScottC replied on at Permalink Reply
ScottC
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
ScottC replied on at Permalink Reply
ScottC
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?
}
Abs0lute replied on at Permalink Reply
Abs0lute
Sweet!
This helped me not have to make a single page for the homepage. Very nice. How could you add multiple pages?
redkite replied on at Permalink Reply
redkite
Thanks for this - perfect!