WBCE CMS Forum

WBCE CMS – Way Better Content Editing.

Du bist nicht angemeldet.

#1 20.08.2021 10:10:37

losttrip
Mitglied

OFA helpers random

I'm not exactly sure how the oneforall_helpers snippets work, but is it possible to show a random item from a OFA section on a different page.

For example, you have three OFA pages with 10 shop items each (each page is a different Group field).
On the home page, you show three items, one from each page.  Random item showing with each page refresh.  If random is not an option, then just showing the latest, or a specific group from each page, perhaps group ="Featured_Items".

Offline

#2 22.08.2021 13:48:28

florian
Administrator

Re: OFA helpers random

I guess it's not the best solution regarding efficience and performance, but here's an idea based on ofa_anyitems:
1) change 

$output = '';

to

$output = array();

2) change

$output .= trim(str_replace($search, $replace, $setting_item_loop));

to

$output[] = trim(str_replace($search, $replace, $setting_item_loop));

3) change

echo $output;

to

shuffle($output);
echo $output[1];

Explanation: instead of displaying $output immediately, it is written to an array. The PHP command "shuffle" reorders the array elements randomly, so $output[1] changes each time when the function is called.

Btw, just call the function with the OfA section ID as the only parameter, e.g.

oneforall_anyitems(17);

Code allein macht nicht glücklich. Jetzt spenden!

Offline

#3 24.08.2021 10:35:39

losttrip
Mitglied

Re: OFA helpers random

Thank you.  I'll give that a try.

Offline

Fußzeile des Forums

up