<?php
class LatestAdsWidget extends WP_Widget
{
function LatestAdsWidget(){
$widget_ops = array('classname' => 'latest_ads_widget', 'description' => __( "Latest Ad Listings Widget To Display Ads On Blog And Single Ad Sidebar Pages") );
$control_ops = array('width' => 300);
$this->WP_Widget('latestadswidget', __('Latest Ads Widget'), $widget_ops, $control_ops);
}
function widget($args, $instance){
extract($args);
$count = $instance['count'];
if (!is_numeric ($count)) $count = 5;
$title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title']);
$r = new WP_Query(array('post_type' => 'ad_listing', 'posts_per_page' => $count, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'orderby' => 'asc'));
if ($r->have_posts())
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title; ?>
<?php while ($r->have_posts()) : $r->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a>
<?php remove_filter('the_excerpt', 'wpautop'); ?><br /><?php the_excerpt() ?>
<?php endwhile; ?>
<div class="clear"></div>
<?php
echo $after_widget;
}
function update($new_instance, $old_instance){
$instance = $old_instance;
/* Strip tags (if needed) and update the widget settings. */
$instance['title'] = strip_tags($new_instance['title']);
$instance['count'] = (trim(strip_tags($new_instance['count'])));
return $instance;
}
function form( $instance ) {
// load up the default values
$defaults = array( 'title' => 'Listings On Blog Pages', 'count' => 5 );
$instance = wp_parse_args( (array) $instance, $defaults );
?>
<p>
<label><?php _e('Title:') ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" />
</p>
<p>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" value="<?php echo $instance['count']; ?>" style="width:30px;" />
<label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Listings To Show', 'appthemes') ?></label>
</p>
<?php
}
}
function LatestAdsWidgetInit() {
register_widget('LatestAdsWidget');
}
add_action('widgets_init', 'LatestAdsWidgetInit');
?>
There are currently 1 users browsing this thread. (0 members and 1 guests)