WP Widget Assistance

efeezy

New member
Oct 5, 2007
5,250
136
0
50
Can someone take a look at the code below and tell me the best way to make it so it calls from a specific wordpress category id#.

HTML:
/*-----------------------------------------------------------------------------------*/
/*    Widget Setup
/*-----------------------------------------------------------------------------------*/

    function theme_Blog_Widget() {     

        /* Widget settings. */     
        $widget_ops = array( 'classname' => 'theme_blog_widget', 'description' => __('A widget that displays your latest posts with image.', 'framework') );

            /* Widget control settings. */ 
        $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'theme_blog_widget' );

            /* Create the widget. */ 
        $this->WP_Widget( 'theme_blog_widget', __('Custom Blog Widget', 'framework'), $widget_ops, $control_ops );
    }


/*-----------------------------------------------------------------------------------*/      
/*    Display Widget
/*-----------------------------------------------------------------------------------*/

    function widget( $args, $instance ) {     
        extract( $args );

        $title = apply_filters('widget_title', $instance['title'] );         

            /* Our variables from the widget settings. */ 
        $number = $instance['number'];

            /* Before widget (defined by themes). */ 
        echo $before_widget;

            /* Display Widget */ 
        ?> 
        <?php /* Display the widget title if one was input (before and after defined by themes). */
                if ( $title )
                    echo $before_title . $title . $after_title;
                ?>

                <ul class="clearfix">                             

                    <?php                  
                    $query = new WP_Query();
                    $query->query('posts_per_page='.$number.'&caller_get_posts=1');
                    ?>
                    <?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
                    <li class="clearfix">

                        <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) : /* if post has post thumbnail */ ?>                         
                        <a href="<?php the_permalink(); ?>">
                        <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-small' ); ?>
                        <div class="entry-thumb" style="background-image: url('<?php echo $image[0]; ?>'); width:<?php echo $image[1]; ?>px; height:<?php echo $image[2]; ?>px;"></div>
                        </a>
                        <?php endif; ?>

                    <div class="entry-wrap">                         
                    <h4 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                    <a href="<?php the_permalink(); ?>"><img src="/images/playgame.png"></a>

                    </div>  

                    </li>                     
                    <?php endwhile; endif; ?>

                    <?php wp_reset_query(); ?>                     

                    </ul> 

        <?php         

            /* After widget (defined by themes). */ 
        echo $after_widget;
    }


/*-----------------------------------------------------------------------------------*/      
/*    Update Widget
/*-----------------------------------------------------------------------------------*/

    function update( $new_instance, $old_instance ) {     

        $instance = $old_instance;         

        /* Strip tags to remove HTML (important for text inputs). */         
        $instance['title'] = strip_tags( $new_instance['title'] );
        $instance['number'] = strip_tags( $new_instance['number'] );

            /* No need to strip tags for.. */ 

            return $instance; 
    }


/*-----------------------------------------------------------------------------------*/        
/*    Widget Settings
/*-----------------------------------------------------------------------------------*/

    function form( $instance ) {      

            /* Set up some default widget settings. */ 
        $defaults = array(
        'title' => 'Latest From The Blog',

        'number' => 4         

        );         
        $instance = wp_parse_args( (array) $instance, $defaults ); ?>

        <!-- Widget Title: Text Input -->         
        <p>
            <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'framework') ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
        </p>

        <!-- Widget Title: Text Input -->         
        <p>
            <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e('Amount to show:', 'framework') ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" value="<?php echo $instance['number']; ?>" />
        </p>


    <?php          
    }
}
?>