O'Reilly logo

WordPress 3 Plugin Development Essentials by Everett Griffiths, Brian Bondari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating random content

It's time to flesh out the widget() function. This is the function that prints out the content that is visible on the frontend, and we want it to print out some random content. We are going to approach this in phases so that we can test it.

  1. Firstly, add a helper function to ContentRotator.php that generates some random content. For now, we're going to generate a random number. Later, we will pull up some random content from the database, but always keep things simple the first time around so you can test them. Add the following static function to ContentRotator.php:
    /**
    Fetch and return a piece of random content
    */
    static function get_random_content()
    {
    return rand(1, 1000000);
    }
    
  2. This relies on PHP's rand() function, and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required