Welcome to Geeklog, Anonymous Friday, November 29 2024 @ 11:42 pm EST
Geeklog Forums
Random block
I would like to do a random block and I don't know how I could success with that
The idea is following. I have always on my page a block at the same place but each times it's displayed, it's another block content displayed. Sometimes it's the user of the month, a photo from gallery another time, a tip of the day another time yet.
Hope it was clear
David.
The idea is following. I have always on my page a block at the same place but each times it's displayed, it's another block content displayed. Sometimes it's the user of the month, a photo from gallery another time, a tip of the day another time yet.
Hope it was clear
David.
8
11
Quote
Status: offline
Turias
Forum User
Full Member
Registered: 10/20/03
Posts: 807
Well, it sounds easy enough. Just write the X functions you want. Then, write a block like this:
{
$i = rand(1, 3);
switch ($i)
{
case 1:
return phpblock_function1();
case 2:
return phpblock_function2();
case 3:
return phpblock_function3();
}
}
Hope that helps!
Text Formatted Code
function phpblock_randomBlock(){
$i = rand(1, 3);
switch ($i)
{
case 1:
return phpblock_function1();
case 2:
return phpblock_function2();
case 3:
return phpblock_function3();
}
}
Hope that helps!
24
8
Quote
MaxPower
Anonymous
I type this code in to my lib-custom.php file, and get the following error:
Parse error: parse error, unexpected $ in /home/wetcol81/public_html/blog/system/lib-custom.php on line 405
What am I doing wrong?
Thanks!
Parse error: parse error, unexpected $ in /home/wetcol81/public_html/blog/system/lib-custom.php on line 405
What am I doing wrong?
Thanks!
8
12
Quote
Status: offline
1000ideen
Forum User
Full Member
Registered: 08/04/03
Posts: 1298
It would be nice if dgaussin could post the end result if there is any. By chance I am also looking for a random block as follows: (BUT I definitely know nothing about php I just started learning css... I had a look at those random blocks of galeries but I really don`t get it.)
Mambo got a nice feature of "news flashes". It is no more than a block that displays the story text of a story witin a certain topic.
E.g. if there is a topic news_flashes the block shows the storytext or rather just {story_introtext} (or e.g. just the picture included) of one of the stories within topic news_flashes.
So the overall structure would be: Count the number of stories in topic news_flashes, choose one of them, display {story_introtext}
Anybody accidentally about to build such a block???
Mambo got a nice feature of "news flashes". It is no more than a block that displays the story text of a story witin a certain topic.
E.g. if there is a topic news_flashes the block shows the storytext or rather just {story_introtext} (or e.g. just the picture included) of one of the stories within topic news_flashes.
So the overall structure would be: Count the number of stories in topic news_flashes, choose one of them, display {story_introtext}
Anybody accidentally about to build such a block???
9
12
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
Quote by 1000ideen:
So the overall structure would be: Count the number of stories in topic news_flashes, choose one of them, display {story_introtext}
Anybody accidentally about to build such a block???
So the overall structure would be: Count the number of stories in topic news_flashes, choose one of them, display {story_introtext}
Anybody accidentally about to build such a block???
Text Formatted Code
function phpblock_randomStory()
{
global $_TABLES, $_CONF;
$result = DB_query("SELECT sid,tid,title,introtext FROM {$_TABLES['stories']}
WHERE (draft_flag = 0) AND (date <= NOW())"
. COM_getPermSQL ('AND') . " ORDER BY RAND LIMIT 1");
if( DB_numRows($result) > 0 ){
$A = DB_fetchArray( $result );
$retval = '<a href="' . COM_buildUrl( $_CONF['site_url']
. '/article.php?story=' . $A['sid'] ) . '">'
. COM_stripslashes($A['title'])
. '</a> (' . $A['hits'] . ')<br>';
$retval .= '<div class="introtext">' . COM_stripslashes($A['introtext']) . '</div>';
return $retval;
}
}
14
11
Quote
All times are EST. The time is now 11:42 pm.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content