";
$line_end = "
\n";
$closing = "
\n";
break;
case "p":
$opening = "";
$line_end = "
\n";
break;
case "ul":
default:
$string_to_echo .= "\n";
$opening = "- ";
$line_end = "
\n";
$closing = "
\n";
}
for ($x=0;$x 0 ) $string_to_echo .= $opening;
$string_to_echo .= ''.$rand_articles[$x]['title'].'';
if (strlen($line_end) > 0) $string_to_echo .= $line_end;
}
$string_to_echo .= 'Widget By Valance Bedding';
if (strlen($closing) > 0) $string_to_echo .= $closing;
return $string_to_echo;
}
function get_random_pages($numPosts) {
global $wpdb, $wp_db_version;
$options = (array) get_option('widget_randompages');
$posts = $options['posts'] ? $options['posts'] : 'both';
$sql = "";
switch($posts)
{
case "posts":
$sql = "SELECT $wpdb->posts.ID FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post'";
break;
case "pages":
$sql = "SELECT $wpdb->posts.ID FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page'";
break;
default:
$sql = "SELECT $wpdb->posts.ID FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' OR $wpdb->posts.post_type = 'post'";
}
$the_ids = $wpdb->get_results($sql);
$luckyPosts = (array) array_rand($the_ids,($numPosts > count($the_ids) ? count($the_ids) : $numPosts));
$sql = "SELECT $wpdb->posts.post_title, $wpdb->posts.ID";
$sql .= " FROM $wpdb->posts";
$sql .= " WHERE";
# Here we minimize number of query to the database by using ORs - just one query needed
foreach ($luckyPosts as $id)
{
if($notfirst) $sql .= " OR";
else $sql .= " (";
$sql .= " $wpdb->posts.ID = ".$the_ids[$id]->ID;
$notfirst = true;
}
$sql .= ')';
$rand_articles = $wpdb->get_results($sql);
# Give it a shuffle just to spice it up
shuffle($rand_articles);
if ($rand_articles)
{
foreach ($rand_articles as $item)
{
$posts_results[] = array('title'=>str_replace('"','',stripslashes($item->post_title)),
'permalink'=>post_permalink($item->ID)
);
}
return $posts_results;
}
else
{
return false;
}
}
function widget_randompages_control() {
$options = $newoptions = get_option('widget_randompages');
if ( $_POST['randompages-submit'] ) {
$newoptions['title'] = strip_tags(stripslashes($_POST['randompages-title']));
$newoptions['type'] = $_POST['randompages-type'];
$newoptions['count'] = (int) $_POST['randompages-count'];
$newoptions['posts'] = $_POST['randompages-posts'];
}
if ( $options != $newoptions ) {
$options = $newoptions;
update_option('widget_randompages', $options);
}
$list_type = $options['type'] ? $options['type'] : '