Page 1 of 1
Random Blocks of Text?
Posted: Sat 9. Dec 2006, 03:35
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.
Posted: Sat 9. Dec 2006, 07:44
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
Posted: Wed 23. May 2007, 10:34
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]
Posted: Wed 23. May 2007, 10:41
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
Posted: Wed 23. May 2007, 11:34
by Vuk
Oliver Georgi wrote:
Schön sauber halten.
Oh stimmt, da kann man sparen. Ein weiterer Schritt auf meinem Fussweg der Erleuchtung.

Posted: Sat 22. Sep 2007, 11:11
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 ...
Posted: Tue 13. Nov 2007, 13:28
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?
Posted: Tue 13. Nov 2007, 16:04
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!
Posted: Tue 13. Nov 2007, 18:30
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]
Posted: Wed 14. Nov 2007, 07:02
by fopulu
@markus s:
Danke, das sieht gut aus!
Bei deinen Zitaten auf der rechten Seite fehlt aber der Abschluß der Box, sprich die runden Ecken..... guck mal nach.
Posted: Fri 16. Nov 2007, 09:32
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!