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.
- 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 ...
Get WordPress 3 Plugin Development Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.