Results 1 to 2 of 2

Thread: SM Sticky Featured Widget ?

  1. #1
    Thread Starter
    Newbie altm's Avatar
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question SM Sticky Featured Widget ?

    Hello,

    Do you know the WordPress plugin named "SM Sticky Featured Widget" for ClassiPress ? Well here the link below :
    http://wordpress.org/extend/plugins/...t/screenshots/

    I would like to know if someone know how to modify that plugin for "Showing only the specific category" ?

    I found this code below, line 34 :
    PHP Code:
            elseif(is_category()) {
                
    $term get_term_by('id'get_cat_ID(single_cat_title(""false)), 'category');
            } 
    Here is the full code below :
    PHP Code:
    <?php
    /*
    Plugin Name: SM Sticky Featured Widget
    Plugin URI: http://sethmatics.com/extend/plugins/sm-sticky-widget
    Description: A tiny but high in demand widget to post sticky or "featured" posts into any widget area complient with ClassiPress.
    Author: Seth Carstens
    Version: 1.2.0
    Author URI: http://sethmatics.com/
    */

    // Register the widget.
    add_action('widgets_init'create_function('''return register_widget("WP_Widget_smSticky");'));

    class 
    WP_Widget_smSticky extends WP_Widget {

        
    // The widget construct instatiates the widget
        
    function WP_Widget_smSticky() {
            
    $widget_ops = array( 'classname' => 'widget_smSticky''description' => __"SM Sticky Featured Posts" ) );
            
    $this->WP_Widget('smSticky'__('SM Sticky Posts'), $widget_ops);
        } 
    // End function WP_Widget_smSticky

        // This code displays the widget on the screen.
        
    function widget($args$instance) {
            
    wp_reset_query();
            
    extract($args);
            
            
    //detect and set configuration for classipress or standard wordpress theme
            
    if(post_type_exists('ad_listing')) { $cp true$postType 'ad_listing'$catType 'ad_cat'; }
            else { 
    $cp false$postType 'post'$catType 'category'; }
            
            if(
    get_query_var('taxonomy')) {
                
    $term get_term_by('slug'get_query_var('term'), get_query_var('taxonomy'));
            }
            elseif(
    is_category()) {
                
    $term get_term_by('id'get_cat_ID(single_cat_title(""false)), 'category');
            }
            elseif(
    is_single()) { //single page
                
    $terms wp_get_post_terms(get_the_ID(), $catType); //print_r($terms); exit;
                
    $term $terms[0];
            }

            
    /* User-selected settings. */
            //title
            
    $title apply_filters('widget_title'$instance['title'] );
            
    //number of posts (if never saved, defaults to 5
            
    if ( !$number = (int) $instance['number'] ) $number 5;
            else if ( 
    $number $number 1;
            else if ( 
    $number 15 $number 15;
            
    //thumbnails
            
    $showthumbs = isset( $instance['showthumbs'] ) ? $instance['showthumbs'] : false;
            
    $catTitles = isset( $instance['catTitles'] ) ? $instance['catTitles'] : false;
            
            
    //determine the sticky post type (custom post types)
            
    if(post_type_exists('ad_listing')) $postType 'ad_listing';
            else 
    $postType 'post';
            
            
    //always use these attributes when loading the query
            
    $queryArrayOrString = array(
                
    'post_type' => $postType,
                
    'posts_per_page' => $number,
                
    'orderby' => 'rand',
                
    'post_status' => 'publish');
            if(
    $instance['showType'] == 'sticky'$queryArrayOrString['post__in'] = get_option('sticky_posts');
            else if(
    $instance['showType'] == 'reg'$queryArrayOrString['post__not_in'] = get_option('sticky_posts');
            
            
    //if there is a term, only display featured ads from that term assuming the option is turned on
            
    if($term->slug && $catTitles) {
                if(
    $cp$queryArrayOrString['ad_cat'] = $term->slug;
                else 
    $queryArrayOrString['category_name'] = $term->slug;
            }
            
    $smStickyPosts = new WP_Query($queryArrayOrString);
            
            
    //start printing the widget
            
    echo $before_widget;
            
            
    //if not on the home page, we must be in a category, display that title instead.
            
    if( !is_home() && $catTitles) echo $before_title __('Featured in ') . $term->name $after_title;    
            
    //means this is the home page : use defined title and exclude blog category ID's
            
    else {
                if(isset(
    $instance['title'])) echo $before_title $instance['title'] . $after_title;
                else  echo 
    $before_title __('Sticky Posts''cp') . $after_title;            
            }
            
            
    //The Loop (modified)
            
    echo '<ul class="featured-sidebar">';
            
    $i 0;
            if(!
    $smStickyPosts->have_posts()) echo 'No Featured Posts Found';
            while (
    $smStickyPosts->have_posts() && ($i $smStickyPosts->query_vars['posts_per_page'])) : $smStickyPosts->the_post();
                if(
    post_type_exists('ad_listing')) : 
            
    ?>
                <li>
                    <div class="post-thumb" style="min-width:50px;">
                        <?php if(function_exists('cp_ad_featured_thumbnail') && $showthumbscp_ad_featured_thumbnail();
                    elseif (
    has_post_thumbnail() && $showthumbs){
                        echo 
    '<a href="' get_permalink() . '">';
                        
    the_post_thumbnail(array(get_option('thumbnail_size_w'),get_option('thumbnail_size_h')), array('class' => 'alignleft'));
                        echo 
    '</a>';
                    }     
    ?>
                    </div>
                    <h3><a href="<?php the_permalink(); ?>"><?php if (mb_strlen(get_the_title()) >= 40) echo mb_substr(get_the_title(), 040).'...'; else the_title(); ?></a></h3>
                    <p class="side-meta"><span class="folder"><?php if (get_the_category()) the_category(', '); else echo get_the_term_list($post->ID'ad_cat'''', '''); ?></span> | <?php if(get_post_meta(get_the_ID(), 'price'true)) cp_get_price_legacy(get_the_ID()); else cp_get_price(get_the_ID(), 'cp_price'); ?></p>
                    <p><?php echo mb_substr(strip_tags(get_the_content()), 0160).'...';?></p>
                </li>
                <?php
                
    else :    
                    echo 
    '<li>';
                    if(
    function_exists('cp_ad_featured_thumbnail') && $showthumbscp_ad_featured_thumbnail();
                    elseif (
    has_post_thumbnail() && $showthumbs){
                        echo 
    '<a href="' get_permalink() . '">';
                        
    the_post_thumbnail(array(get_option('thumbnail_size_w'),get_option('thumbnail_size_h')), array('style' => 'float: left; width: 50px; height: 50px; margin-right: 5px;'));
                        echo 
    '</a>';
                    }        
                    echo 
    '<a href="' get_permalink() . '">' get_the_title() . '</a>';
                    echo 
    '<p style="margin: 0px;">'.mb_substr(strip_tags(get_the_content()), 0160).'...'.'</p>';
                    echo 
    '<br style="clear: both;" />';
                    echo 
    '</li>';
                endif;
                
    $i++;
            endwhile;
            echo 
    '</ul>';
            
    //End of The Loop
            
    echo $after_widget;
            
            
    //debug printing
            //echo 'query_vars <pre>'; print_r($smStickyPosts->query_vars); echo '</pre>';
            //echo '$queryArrayOrString <pre>'; print_r($queryArrayOrString); echo '</pre>';
            //echo '$term <pre>'; print_r($term); echo '</pre>';
            
    wp_reset_query();
        } 
    // End function widget.
        
        
        
        // Updates the settings.
        
    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['number'] = (int) $new_instance['number'];
            
    $instance['showthumbs'] = isset($new_instance['showthumbs']) ? 0;
            
    $instance['catTitles'] = isset($new_instance['catTitles']) ? 0;
            
    $instance['showType'] = $new_instance['showType'];
            return 
    $instance;
        } 
    // End function update
        
        
        
        // The admin form.
        
    function form($instance) {    
        
    $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
        if ( !isset(
    $instance['number']) || !$number = (int) $instance['number'] ) $number 5;
    ?>
    <div id="smSticky-admin-panel">
        <p><label for="<?php echo $this->get_field_id("title"); ?>">Title:</label>
        <input type="text" class="widefat" name="<?php echo $this->get_field_name("title"); ?>" id="<?php echo $this->get_field_id("title"); ?>" value="<?php echo $instance["title"]; ?>" /></p>

        <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
        <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number?>" size="3" /></p>

        <p><input class="checkbox" type="checkbox" <?php checked$instance['showthumbs'], true ); ?> id="<?php echo $this->get_field_id'showthumbs' ); ?>" name="<?php echo $this->get_field_name('showthumbs'); ?>" />
        <label for="<?php echo $this->get_field_id('showthumbs'); ?>"> Display Thumbnails?</label></p>
        
        <p><input class="checkbox" type="checkbox" <?php checked$instance['catTitles'], true ); ?> id="<?php echo $this->get_field_id'catTitles' ); ?>" name="<?php echo $this->get_field_name('catTitles'); ?>" />
        <label for="<?php echo $this->get_field_id('catTitles'); ?>"> Only show sticky posts of the post category & sub categories?</label></p>
        
        <p><label for="<?php echo $this->get_field_id('showType'); ?>"> Posts to display: </label>
            <select class="dropdown" id="<?php echo $this->get_field_id'showType' ); ?>" name="<?php echo $this->get_field_name('showType'); ?>">
                <option value="sticky" <?php selected$instance['showType'], 'sticky' ); ?>>Sticky</option>
                <option value="all" <?php selected$instance['showType'], 'all' ); ?>>All</option>
                <option value="reg" <?php selected$instance['showType'], 'reg' ); ?>>Non-Sticky</option>
            </select></p>
        </div>
        
    <?php
        
    // end function form

    // end class WP_Widget_smSticky

    ?>
    Thanks !

  2. #2
    jomarkosabel's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    40,928
    Thanks
    168
    Thanked 3,403 Times in 3,274 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!
    Please help our moderating team work more efficiently by not sending us support questions via PM. You can read more about how AppThemes support works here. However, you can send a PM to follow up and remind me if I missed your support request/thread.

    Thank you and have a nice day.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Where to manage featured ads (sticky)
    By endoo in forum Report ClassiPress Bugs
    Replies: 2
    Last Post: September 25th, 2011, 08:16 AM
  2. SM Sticky Featured Widget - weird error with price field?
    By Leigh in forum Report ClassiPress Bugs
    Replies: 4
    Last Post: September 5th, 2011, 02:46 PM
  3. Featured Ad (sticky)
    By massimorufo in forum Report ClassiPress Bugs
    Replies: 4
    Last Post: December 12th, 2010, 02:25 PM
  4. No Featured Ads.. but Sticky?
    By mrfraz in forum Help Using ClassiPress
    Replies: 2
    Last Post: April 4th, 2010, 06:28 PM