random block to display data from any of 300+ pages

Permalink
I have been building a C5 site with 300+ pages containing mostly bios. The client would like to show a random headshot image with the persons name and when clicked it should direct you to the bio page for that information.

Any ideas on the best way to tackle this?

tommyh
 
jero replied on at Permalink Reply
jero
Don't know how you've structured the bio blocks on your page or even if you're using specific blocks for the bio information, but..

hopefully you've done something like use the Designer Content addon to create a custom "bio" block, and dropped them into the Main area, you could try something like this:

$page = Page::getByID($randompageid);
$blocks = $page->getBlocks('Main');
foreach($blocks as $b){
    if ($b->getBlockTypeHandle()=='bio')
    $b->display();
}


You'd have to figure out some method of producing $randompageid.....

P.S. If you've not checked out designer content, you should. It's awesome.http://www.concrete5.org/marketplace/addons/designer-content/...
JohntheFish replied on at Permalink Reply
JohntheFish
php array_rand() or shuffle()
tommyh replied on at Permalink Reply
tommyh
Thanks so much for the reply! Very helpful!

Oh how I wish I had that a month ago! :)

The bios are all separate pages created by the bio name using multiple page add-on. The are sorted alphabetically by Alphabet letter and last name.

I will give Designer Content a look. :(

I am guessing you can make the whole page a designer look?

$randompageid and other code to only show the name and headshot on the homepage that when clicked goes to that full page... Could that be possible using this method?

After launch in 2 weeks I may start to rework into Designer Content as we move forward.

Would love to hear others thoughts on this goal...
jero replied on at Permalink Best Answer Reply
jero
Assuming the use of Designer content, in the block folder copy your view.php to a new subfolder templates/random/view.php. Hack this view to include just the parts(photo title etc) that you want to display. Then specify a custom template to use setCustomTemplate('templates/random')

I.E.

$page = Page::getByID($randompageid);
$blocks = $page->getBlocks('Main');
foreach($blocks as $b){
    if ($b->getBlockTypeHandle()=='bio') {
        $b->setCustomTemplate('templates/random');
        $b->display();
     }
}
tommyh replied on at Permalink Reply
tommyh
Thanks for the reply. I may have to sub this work out. Would you PM me so I can get a quote from you on accomplishing this

My plate is full and I do not have the time to focus on this coding.
jero replied on at Permalink Reply
jero
PM Sent :)