Welcome to Geeklog, Anonymous Friday, March 29 2024 @ 06:16 am EDT

Geeklog Forums

Random block


Status: offline

dgaussin

Forum User
Junior
Registered: 06/01/03
Posts: 16
thoughtful
I would like to do a random block and I don't know how I could success with that Smile

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 Wink

David.
 Quote

Status: offline

Turias

Forum User
Full Member
Registered: 10/20/03
Posts: 807
Do you know php? Do you at least have php functions for each random block you would like to display?
 Quote

Status: offline

dgaussin

Forum User
Junior
Registered: 06/01/03
Posts: 16
silly
Before to write it myself, I hoped maybe someone has a good and simple idea to do it, or even better, someone has already a block to do it Big Grin

David.
 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:

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!
 Quote

Status: offline

dgaussin

Forum User
Junior
Registered: 06/01/03
Posts: 16
brainy
Oh yes, it very helps. It's a good skeleton to start, I know what to do now..

Thanks,
David.
 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!
 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???

Wink
 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???

Wink

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;
   }
}


 
something like that I think
 Quote

All times are EDT. The time is now 06:16 am.

  • 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