Navigation :

Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Blog
Books
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links




Site Sponsors :

Bookmark :

Links :

finance products
domain names
golfing products

Downloads :

Misc :

Webmaster Resources
Only PHP
ScriptSearch.com
Scripts.com - Get the best scripts NOW!
AndreaPHP Programming

Valid XHTML 1.0 Transitional


Valid CSS!


Random lottery wordpress widget

This example shows how to create a widget in wordpress which will display random numbers

<?php
/*
Plugin Name: UK lottery numbers
Plugin URI: http://www.beginnersphp.co.uk/uklottery.php
Description: Generate numbers for the UK lottery
Author: shedboy
Version: 0.1
Author URI: http://www.beginnersphp.co.uk

Change History
0.1 : First version displays 6 numbers between 1 and 49

*/

//Lottery function, genertates 6 random numbers between 1 and 49
function lottery($maxn = "49",$maxb="6")
{
srand((double) microtime() * 1000000);
while (1>0)
{
$lottery[] = rand(1,$maxn);
$lottery = array_unique($lottery);
if (sizeof($lottery) == $maxb) break;
}
sort($lottery);
return implode(", ",$lottery);
}

function widget_uklottery_init()
{

if ( !function_exists('register_sidebar_widget'))
return;

function widget_uklottery()
{
# this prints the widget
echo $before_widget;
echo $before_title;

$lotterynums = lottery();
echo "<h2>UK Lottery numbers generator</h2>";
echo "<br>$lotterynums<br><br><br>";

echo $after_title;
echo $after_widget;
}

register_sidebar_widget('UK lottery Widget', 'widget_uklottery');
}

add_action('widgets_init', 'widget_uklottery_init');
?>