Hi,
I'm looking for the best way to display a random unpublished Zenpage page on my index page.
In fact I have 5 unpublished pages made with Zenpage, I'd like to use or to build a function to display randomly one from them (and only from them) each time the home page is loaded.
Now, I use that kind of code to display (unrandomly) an unpublished page :
Do you have any idea about the best way to proceed ?
Thank you for your time.
You probably could modifythe randomimages() function we have.
You could also build your own function. The easiest would probably be to get the unpublished pages via getPages() (refering to the nightly) into an array and then use the standard php functions rand() and srand() to get a random page from them.
Hi Malte,
Thank you for your answer.
I can't find any getPages() functions documentation here :
http://www.zenphoto.org/documentation-svn/elementindex.html
I'm trying the second option and build my own function.
In a customfunctions.php file I add this code (found elsewhere, I'm a php nightmare) :
function randomtxt() { $breves=array( "$printPageContent($titlelink='titletink-of-the-text-01',$published=false);", "$printPageContent($titlelink='titletink-of-the-text-02',$published=false);", "$printPageContent($titlelink='titletink-of-the-text-03',$published=false);", "$printPageContent($titlelink='titletink-of-the-text-04',$published=false);", "$printPageContent($titlelink='titletink-of-the-text-05',$published=false);", "$printPageContent($titlelink='titletink-of-the-text-06',$published=false);" ); $num_breve=rand(0, sizeof($breves) ); echo $breves[$num_breve]; }
but (of course...) it doesn't work : printPageContent, titlelink and published are considered as Undefined variables.
Do you have any idea about it ?
I am sorry, the Zenphoto svn doc is a little out dated and the Zenpage doc not incorporated yet. It is still separate on the project site. Also if you try to work with an array you should use the "get" variant as the "print" variant echos:
http://zenpage-functions.maltem.de/zenpage/_zenpage-template-functions.php.html#functiongetPageContent
Also the correct usage would be getPageContent('titletink-of-the-text-01',false);. Maybe a better way to load the array is if you know the exact number of pages:
$breves = array(); $breves[0] = getPageContent('titletink-of-the-text-01',false); etc