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.
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 toContentRotator.php
:/** Fetch and return a piece of random content */ static function get_random_content() { return rand(1, 1000000); }
This relies on PHP's
rand()
function, and it returns a random number between one and 1,000,000. It will suffice for our current testing.Before we go much further, let's "templatize" our widget output. This is another case where the solutions offered on most websites and in most books would...