Home
Download
Add-ons
Help
Forum
Organisation
Project
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
May 25, 2012, 09:15:03 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Interested in joining the WebsiteBaker team?
For more Information read
here
or on our
new website
.
155527
Posts in
21712
Topics by
7737
Members
Latest Member:
chris85
WebsiteBaker Community Forum
English
Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
(Moderator:
Argos
)
Snippet: WbRandomSection
Pages: [
1
]
Go Down
Author
Topic: Snippet: WbRandomSection (Read 1718 times)
WebBird
Guest
Snippet: WbRandomSection
«
on:
August 04, 2009, 01:16:00 PM »
Due to a request in the German board, I created a RandomSection Snippet. I am aware of the existence of "RandomSection", but I think it is too restrictive, for it limits the sections to choose from to WYSIWYG.
So, I created a Snippet called "WbRandomSection" (where Wb is for Webbird
), which gives you more freedom.
For download, see the AMASP page:
http://www.websitebakers.com/pages/modules/listings/section-pages/wbrandomsection.php?lang=EN
Usage instruction can be found in the readme.txt:
Quote
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 occur
3. 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 pages
show_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.randomsectionwrap { width: 100px; float: right; }
«
Last Edit: August 04, 2009, 01:40:43 PM by WebBird
»
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4884
Re: Snippet: WbRandomSection
«
Reply #1 on:
August 04, 2009, 01:36:42 PM »
Thanks again WebBird.
Thats a very handy Snippet.
Regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
Re: Snippet: WbRandomSection
«
Reply #2 on:
August 04, 2009, 01:41:09 PM »
Logged
crnogorac081
AddOn Development
Offline
Posts: 1706
Re: Snippet: WbRandomSection
«
Reply #3 on:
August 04, 2009, 02:15:36 PM »
can you put sections id in array ?
Logged
Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4884
Re: Snippet: WbRandomSection
«
Reply #4 on:
August 04, 2009, 02:33:20 PM »
Hello Ivan,
All you need to do is: name your pageID.
The snippet returns the sections of this pageID in random.
So you do not have to call the sections in a array.
But f you need it that way, there is another module for this at AMASP.
Regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
crnogorac081
AddOn Development
Offline
Posts: 1706
Re: Snippet: WbRandomSection
«
Reply #5 on:
August 04, 2009, 02:39:36 PM »
I ment if sections are on different pages..
But if there is already exist cool
cheers
Logged
Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
WebBird
Guest
Re: Snippet: WbRandomSection
«
Reply #6 on:
August 04, 2009, 03:01:42 PM »
Hum? Do you want to give a list of sections to choose from? If so, you don't need the snippet.
By default, a random section will be chosen from ALL active sections on ALL pages.
Logged
crnogorac081
AddOn Development
Offline
Posts: 1706
Re: Snippet: WbRandomSection
«
Reply #7 on:
August 04, 2009, 03:20:47 PM »
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 ?
Logged
Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4884
Re: Snippet: WbRandomSection
«
Reply #8 on:
August 04, 2009, 03:42:17 PM »
Quote from: crnogorac081 on August 04, 2009, 03:20:47 PM
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 ?
I think this is the module you're looking for.
But notice, that it handles WYSIWYG only.
Regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
Re: Snippet: WbRandomSection
«
Reply #9 on:
August 05, 2009, 09:03:07 AM »
The original RandomSection module only handles WYSIWYG.
WbRandomSection handles any section/module type.
I can add the option to give a list of section id's to choose from, but I think you could do it as a droplet.
Try this code (untested) in a code section:
Code:
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;
In
Code:
$sections = array();
, insert the comma seperated section IDs between the (...).
«
Last Edit: August 05, 2009, 10:35:43 AM by WebBird
»
Logged
crnogorac081
AddOn Development
Offline
Posts: 1706
Re: Snippet: WbRandomSection
«
Reply #10 on:
August 05, 2009, 11:19:26 AM »
cool.
It is important that it can use any section
cheers
Logged
Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
WebBird
Guest
Re: Snippet: WbRandomSection
«
Reply #11 on:
August 05, 2009, 11:24:14 AM »
With the WbRandomSection snippet you can, but you can't give a list of sections to choose from. Maybe in the next version.
Logged
mr-fan
Offline
Posts: 1556
Re: Snippet: WbRandomSection
«
Reply #12 on:
August 25, 2009, 07:13:34 AM »
for WB 2.8 there was a missing index.php file in the zip...
attached file with index.php
regards martin (thanks to doc - he figured this out...)
Logged
WebBird
Guest
Re: Snippet: WbRandomSection
«
Reply #13 on:
August 26, 2009, 09:52:01 AM »
Updated version 0.3 uploaded to AMASP.
Logged
Pages: [
1
]
Go Up
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General Announcements
=> Security Announcements
=> Documentation
=> WebsiteBaker Website Showcase
=> Guest Area & Off-Topic
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.9
===> Announcements
===> Help/Support
=====> Modules / Extensions
===> Suggestions
===> Software bugs
=> Help & Support
=> Modules
=> Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
=> jQuery
=> Templates, Menus & Design
=> WebsiteBaker Language Files
=> WebsiteBaker 2.x discussion
=> WebsiteBaker 3
=> Archive (posts up to 2007)
-----------------------------
Deutsch (German)
-----------------------------
=> Ankündigungen
=> WebsiteBaker 2.9
===> Ankündigungen
===> Hilfe/Support
=====> Module / Extensions
===> Vorschläge
===> Softwarefehler
===> Erfahrungs und Testberichte
=> Hilfe/Support
=> Module & Snippets
=> Templates & Design
=> Tutorials
=> jQuery
=> Diskussion über WB
=> Off-Topic
=> Archiv für Themen bis 2007
-----------------------------
Nederlands (Dutch)
-----------------------------
=> Aankondigingen
=> Hulp & Ondersteuning
=> Niet-Terzake (Off Topic)
-----------------------------
Francais (French)
-----------------------------
=> Help/Support
-----------------------------
Italiano (Italian)
-----------------------------
=> Help/Support
-----------------------------
Bakery (WB shop module)
-----------------------------
=> Bakery English
=> Bakery Deutsch
-----------------------------
KeepInTouch (Multi Contact Module)
-----------------------------
=> KeepInTouch English
=> KeepInTouch Deutsch
Loading...