WebsiteBaker 2.13.9 is now available!
R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WBhttps://forum.websitebaker.org/index.php/topic,32355.0.html
USAGE=====1. In a Code section* Add a code section to the page* Insert the following code (the two lines between --- and ---):---include_once WB_PATH.'/modules/wbrandomsection/include.php';show_random( array( <Option> ) );---2. In a template* Open the index.php of the template* Insert the code mentioned above where the random section(s) shall occur3. As a droplet* Name: WBRandomSection* Code:---include_once WB_PATH.'/modules/wbrandomsection/include.php';$options = array();if ( isset( $page_id ) ) { $options['page_id'] = $page_id;}if ( isset( $types ) ) { $options['types'] = explode( ',', $types );}if ( isset( $limit ) ) { $options['limit'] = $limit;}ob_start();show_random( $options );$return = ob_get_clean();return $return;---* Comment: [[WBRandomSection?page_id=<ID>;types=<Type(s)>;limit=<Int>]]Examples:[[WBRandomSection?page_id=5]][[WBRandomSection?types=wysiwyg,imagegallery,code]][[WBRandomSection?page_id=5;types=wysiwyg,imagegallery,code]]OPTIONS=======There are several options to control the snippet's behaviour:page_id => <Number> A page number to choose the sections from. By default, the section is chosen from all sections of all pages.types => '<Moduletype>' | array( 'List', 'of', 'Types' ) Module types to choose from. May be a string or a list. By default, the section is chosen from all available module types. limit => <Number> Number of sections to show. Default is 1. EXAMPLES========* All default; choose a (=one) random section from all available pagesshow_random();* Show 2 random sections from page with ID 5, but only of type "wysiwyg" or "imagegallery".show_random( array( 'page_id' => 5, 'limit' => 2, 'types' => array( 'wysiwyg', 'imagegallery' ) )); STYLES======To style your Random Sections, two CSS classes are provided:div.randomsection Each section is wrapped into a <div> of class "randomsection". To add a gray border to each section, for example, add this code to your frontend.css (of the template you are using): div.randomsection { border: 1px solid #ccc; } To add a margin on the bottom of each section, try this: div.randomsection { margin-bottom: 15px; }div.randomsectionwr ap Wraps the complete RandomSection part. That is, if you include more than one section, the complete list of rendered sections is wrapped into a <div> of class "randomsectionwrap". You can use this to "float" the complete RandomSection block: div.randomsectionwr ap { width: 100px; float: right; }
I was thinking maybe to have in array section id like (5,10,20,21) and then to chose random between those 4..Does it metter which module is it, or any module can work ?
global $database;$sections = array();// get random section id$rand = rand( 0, sizeof($sections) );$section_id = $sections[$rand];// get module type from DB$result = $database->query( "SELECT module FROM ".TABLE_PREFIX."sections WHERE section_id='$section_id'" );if ( $result ) { $data = $result->fetchRow(); $module = $data['module']; $file = WB_PATH.'/modules/'.$module.'/view.php'; if ( file_exists ($file) ) { ob_start(); // Output Buffer start require($file); $foo = ob_get_contents(); // put Output Buffer in $foo ob_end_clean(); // end and clean the Output Buffer $output .= '<div class="randomsection">' . $foo . '</div>'; return $output;}return false;
$sections = array();