Results 1 to 2 of 2

Thread: Mod for arbitrary number of items in Popular Overall and Popular Today widgets

  1. #1
    Thread Starter
    scharpliving's Avatar
    Join Date
    Nov 2012
    Location
    United States
    Posts
    12
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Mod for arbitrary number of items in Popular Overall and Popular Today widgets

    I made the following changes in classipress/includes/theme-widgets.php. These changes will let you enter an arbitrary number of ads to display in the Popular Overall and Popular Today widgets. Typical child theme and use at your own risk warnings. Anyways, I don't know why classipress doesn't include this with the theme. Why hard code 10 ads into the widgets? So with this you have an option and can change it anytime through the widget interface. Attachment shows an example.

    Code:
    // classipress sidebar top ads today widget
    // modified by Lyle to enable choosing number of items shown
    class CP_Widget_Top_Ads_Today extends WP_Widget {
    
    	function CP_Widget_Top_Ads_Today() {
    		$widget_ops = array( 'description' => __( 'Your sidebar top ads today', APP_TD ) );
    		$this->WP_Widget( 'top_ads', __( 'CP Top Ads Today', APP_TD ), $widget_ops );
    	}
    
    	function widget( $args, $instance ) {
    
    		extract($args);
    		$title = apply_filters('widget_title', empty($instance['title']) ? __( 'Popular Ads Today', APP_TD ) : $instance['title']);
    
    		echo $before_widget;
    		if ( $title ) echo $before_title . $title . $after_title;
    
    		cp_todays_count_widget(APP_POST_TYPE, $instance['item_count']);
    		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
    	}
    }
    
    
    // classipress sidebar top ads overall widget
    // modified by Lyle to enable choosing number of items shown
    class CP_Widget_Top_Ads_Overall extends WP_Widget {
    
    	function CP_Widget_Top_Ads_Overall() {
    		$widget_ops = array( 'description' => __( 'Your sidebar top ads overall', APP_TD ) );
    		$this->WP_Widget( 'top_ads_overall', __( 'CP Top Ads Overall', APP_TD ), $widget_ops );
    	}
    
    	function widget( $args, $instance ) {
    
    		extract($args);
    		$title = apply_filters('widget_title', empty($instance['title']) ? __( 'Popular Ads Overall', APP_TD ) : $instance['title']);
    
    		echo $before_widget;
    		if ( $title ) echo $before_title . $title . $after_title;
    		//echo '<div>';
    		cp_todays_overall_count_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
    	}
    }
    Attached Images Attached Images

  2. The Following User Says Thank You to scharpliving For This Useful Post:

    rubencio (February 10th, 2013)

  3. #2
    rubencio's Avatar
    Join Date
    May 2010
    Location
    Spain
    Posts
    3,804
    Thanks
    268
    Thanked 316 Times in 278 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

    r u b e n c i o . c o m


    Since 2010 providing AppThemes solutions,
    Plugins and the best childthemes...



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Display thumbnails in sidebar widgets (Popular today & Popular overall)
    By mistercyril in forum ClassiPress General Discussion
    Replies: 8
    Last Post: April 19th, 2016, 02:26 PM
  2. Problem With Popular Ads Today
    By kizafair in forum ClassiPress General Discussion
    Replies: 7
    Last Post: March 12th, 2012, 06:01 PM
  3. [SOLVED] Change on Popular Ads Today & Popular Ads Overall widgets :)
    By homme143 in forum Report ClassiPress Bugs
    Replies: 2
    Last Post: March 14th, 2011, 01:16 AM
  4. Popular Ads Today
    By espinosae in forum ClassiPress General Discussion
    Replies: 1
    Last Post: January 30th, 2011, 05:06 AM
  5. Popular Ads Today bug?
    By doctorcilantro in forum Report ClassiPress Bugs
    Replies: 4
    Last Post: November 3rd, 2010, 10:28 PM