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

Randomizing content from the database

The stars are in alignment—we have custom content in the database, we have a widget that displays content, and choosing the random content all depends on a single function: ContentRotator::get_random_content(). Let's update that function, so it pulls our content from the database:

static function get_random_content(){ $separator = get_option('content_rotation_content_separator'); $content_block = get_option('content_rotation_content_block'); // Ensure that the user has entered valid settings if ( empty($content_block) ) { return ''; } elseif (empty($separator)) { return $content_block; } // Get an array of non-empty chunks $content_array = explode($separator, $content_block); $sanitized_array = array(); foreach ...

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