Random Blocks of Text?

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
User avatar
forefront
Posts: 96
Joined: Sun 16. May 2004, 14:13
Location: Cherryvale, KS • USA
Contact:

Random Blocks of Text?

Post by forefront »

I don't know if this is even possible. In the same way that {RANDOM} randomly selects and displays an image, is it possible to randomly select and display a block of text? I guess this would be semi-dynamic content.
Don Bledsoe
FOREFRONT INTERNET
User avatar
Oliver Georgi
Site Admin
Posts: 9918
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

Yes, it's possible in combination of {SHOW_CONTENT} and an array where a content value is choosen by random.

I will implement such random feature in it.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
Vuk
Posts: 6
Joined: Sun 11. Mar 2007, 13:25

Post by Vuk »

Oliver Georgi wrote: I will implement such random feature in it.

Oliver

Ich weiss nicht ob schon getan aber nicht dokumentiert...

Für alle PHP-Learning-By-Doing-Fussgänger wie mich hier mal ein Beispiel:

[PHP]
// Ein Array basteln, mit den
// ContentPart-IDs, die als
// Pool für die per Zufall
// auszuwählenden dienen sollen
// In diesem Fall 6 Stück
$a=array(385,387,388,389,390,391);

// Das Ganze durch den Mixer jagen
shuffle($a);

// Aus den neu geordneten IDs von vorn
// beginnend welche herauspicken (PHP-Lotto)
// In diesem Fall 3 Stück
$rand1=$a[0];
$rand2=$a[1];
$rand3=$a[2];

// Und jetzt anzeigen lassen
echo '{SHOW_CONTENT:CP,'; print_r($rand1); echo ','; print_r($rand2); echo ','; print_r($rand3); echo '}';
[/PHP]
intentionally left blank
User avatar
Oliver Georgi
Site Admin
Posts: 9918
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

Code: Select all

[PHP]
$a = array(385,387,388,389,390,391);
shuffle( $a );
echo '{SHOW_CONTENT:CP,' . $a[0] . ',' . $a[1] . ',' . $a[2] . '}';
[/PHP]
Schön sauber halten.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
Vuk
Posts: 6
Joined: Sun 11. Mar 2007, 13:25

Post by Vuk »

Oliver Georgi wrote: Schön sauber halten.
Oh stimmt, da kann man sparen. Ein weiterer Schritt auf meinem Fussweg der Erleuchtung. :)
intentionally left blank
User avatar
markus s
Moderator
Posts: 654
Joined: Sat 16. Dec 2006, 19:21
Location: Radfeld / Tirol
Contact:

Post by markus s »

if the cp´s are in a continuously order, (i had 75 cp´s with quotations)
i dissolved this prob with the command 'rand' ...

dazu noch was:
wenn die cp´s in fortlaufender reihenfolge sind (ich hatte zb 75 cp´s
mit zitaten) - dann habe ich einfach ein random mit den cp "von bis"
erstellt.

Code: Select all

[PHP]
$z = rand(286,300); // von cp 286 bis cp 300
echo '{SHOW_CONTENT:CP,' . $z . ',}';
[/PHP]
and again a line saved ...
und wieder eine zeile gespart ...
moderator
propelled by fresh air from tirol
XING|FACEBOOK|OMENTO
fopulu
Posts: 359
Joined: Tue 2. May 2006, 14:19
Location: Rhein-Main

Post by fopulu »

Hat irgendjemand das schon mal irgendwo erfolgreich laufen? Wo?

Ich nehme an, das der Code direkt in der Vorlage eingesetzt wird oder eben als php-Variable innerhalb eines Artikels, oder?
pepe
Posts: 3954
Joined: Mon 19. Jan 2004, 13:46

Post by pepe »

Die einfachste Sache ist doch zum Testen immer, diesen PHP-Konstrukt inerhalb eines HTML-Contentparts in einen Artikel zu legen...

Da kannst du schnell mal das Auge auf ROT schalten... und alles ist wieder weg!
User avatar
markus s
Moderator
Posts: 654
Joined: Sat 16. Dec 2006, 19:21
Location: Radfeld / Tirol
Contact:

Post by markus s »

ja sicher läuft das - einfach hier gucken - rechts die zitate kommen bei jedem aktualiseren als random ... demo
(look at the demo - it runs !)

und sieht so aus (ich habs in die vorlage gepackt, weils auf jeder seite erscheinen soll) -
(i´ve written the code in the template - here it is:)

Code: Select all

<div id="rechts"><div id="zitate">ZITATE:
[PHP]
$z = rand(300,374); //test
echo '{SHOW_CONTENT:CP,' . $z . ',}';
[/PHP]
</div>
{RIGHT}
         </div>
wichtig ist nur dass die Artikel ID´s fortlaufend sind !
all articel id will be serially numbered ...

to all - please talk english (or both)
[/color]
moderator
propelled by fresh air from tirol
XING|FACEBOOK|OMENTO
fopulu
Posts: 359
Joined: Tue 2. May 2006, 14:19
Location: Rhein-Main

Post by fopulu »

@markus s:
Danke, das sieht gut aus! :wink:
Bei deinen Zitaten auf der rechten Seite fehlt aber der Abschluß der Box, sprich die runden Ecken..... guck mal nach.
macmukka

Post by macmukka »

Hi all

You might want to look at this:-

http://www.phpwcms.de/forum/viewtopic.p ... r&start=60

works very nicely and you dont need the sequential ID nums!
Post Reply