// sidebar random ads widget
// created by Lyle (modification of other CP widgets), also enables choosing number of items shown
class CP_Lyle_Widget_Random_Ads extends WP_Widget {
function CP_Lyle_Widget_Random_Ads() {
$widget_ops = array( 'description' => __( 'Your sidebar random ads', APP_TD ) );
$this->WP_Widget( 'random_ads', __( 'Lyle\'s CP Random Ads', APP_TD ), $widget_ops );
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? __( 'Random Ads', APP_TD ) : $instance['title']);
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
//echo '<div>';
lyle_cp_random_widget(APP_POST_TYPE, $instance['item_count']);
//echo "</div>\n";
echo $after_widget;
}
function update($new_instance, $old_instance) {
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
$instance['item_count'] = strip_tags(stripslashes($new_instance['item_count']));
return $instance;
}
function form($instance) {
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', APP_TD ); ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ($instance['title'])) {echo esc_attr( $instance['title']);} ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('item_count'); ?>"><?php _e( 'Items to Display:', APP_TD ); ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('item_count'); ?>" name="<?php echo $this->get_field_name('item_count'); ?>" value="<?php if (isset ($instance['item_count'])) {echo esc_attr( $instance['item_count']);} ?>" />
</p>
<?php
}
}
register_widget('AppThemes_Widget_125_Ads');
register_widget('AppThemes_Widget_Blog_Posts');
register_widget('AppThemes_Widget_Twitter');
register_widget('CP_Widget_Search');
register_widget('CP_Widget_Top_Ads_Today');
register_widget('CP_Widget_Top_Ads_Overall');
register_widget('CP_Lyle_Widget_Random_Ads');
register_widget('AppThemes_Widget_Facebook');
register_widget('CP_Widget_Ads_Tag_Cloud');
// much needed selection of random ads in widget form
// sidebar widget showing random ads
function lyle_cp_random_widget($post_type, $limit) {
global $wpdb;
// get all the post view info to display
$sql = $wpdb->prepare( "SELECT t.postcount, p.ID, p.post_title
FROM $wpdb->app_pop_total AS t
INNER JOIN $wpdb->posts AS p ON p.ID = t.postnum
WHERE p.post_status = 'publish' AND p.post_type = %s
ORDER BY RAND() LIMIT %d", $post_type, $limit );
$results = $wpdb->get_results($sql);
echo '<ul class="pop">';
// must be views today
if ($results) {
foreach ($results as $result)
echo '<li><a href="'. get_permalink($result->ID) .'">'. $result->post_title .'</a> ('. number_format($result->postcount) .' '. __( 'views', APP_TD ) .')</li>';
} else {
echo '<li>' . __( 'No random ads available.', APP_TD ) . '</li>';
}
echo '</ul>';
}
There are currently 1 users browsing this thread. (0 members and 1 guests)