Plugin Directory

Changeset 570953


Ignore:
Timestamp:
07/11/2012 10:49:06 PM (14 years ago)
Author:
kaser
Message:

New features that are *awesome*

Location:
akfeatured-post-widget/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • akfeatured-post-widget/trunk/ak_featured_post.php

    r537752 r570953  
    44Plugin URI: http://cssboss.com/featured_post
    55Description: Easily configure this widget to display any amount of posts (from 1 to 99) from a category into any widgetized area of your blog. Video is more my style, so check out this video tutorial I made for the plugin <a href="http://www.youtube.com/watch?v=eWhafkO7uJQ">Here</a>
    6 Version: 1.5
     6Version: 1.6
    77Author: Andrew Kaser
    88Author URI: http://www.andrewkaser.com
     
    2727
    2828    class ak_featured_post_widget extends WP_Widget {
     29
     30        public function form( $instance ) {
     31            // define all variables of the widget, and also set default values
     32            if ( isset( $instance[ 'category' ] ) ) { $category = $instance[ 'category' ]; } else { $category = __( 'Featured' , 'text_domain' ); }
     33            if ( isset( $instance[ 'title' ] ) ) { $title = $instance[ 'title' ]; } else { $title = __( 'Featured Post' , 'text_domain' ); }
     34           
     35            if ( isset( $instance[ 'show_post_limit' ] ) ) { $show_post_limit = $instance[ 'show_post_limit' ]; } else { $show_post_limit = __( '1' , 'text_domain' ); }
     36            if ( isset( $instance[ 'order_post' ] ) ) { $order_post = $instance[ 'order_post' ]; } else { $order_post = __( 'DESC' , 'text_domain' ); }
     37           
     38            if ( isset( $instance[ 'link_title_to_cat' ] ) ) { $link_title_to_cat = $instance[ 'link_title_to_cat' ]; } else { $link_title_to_cat = __( 'checked' , 'text_domain' ); }
     39            if ( isset( $instance[ 'show_post_title' ] ) ) { $show_post_title = $instance[ 'show_post_title' ]; } else { $show_post_title = __( 'checked' , 'text_domain' ); }
     40           
     41            if ( isset( $instance[ 'show_featured_image' ] ) ) { $show_featured_image = $instance[ 'show_featured_image' ]; } else { $show_featured_image = __( 'checked' , 'text_domain' ); }
     42            if ( isset( $instance[ 'image_align' ] ) ) { $image_align = $instance[ 'image_align' ]; } else { $image_align = __( 'center' , 'text_domain' ); }
     43            if ( isset( $instance[ 'image_size' ] ) ) { $image_size = $instance[ 'image_size' ]; } else { $image_size = __( 'medium' , 'text_domain' ); }
     44            if ( isset( $instance[ 'image_width' ] ) ) { $image_width = $instance[ 'image_width' ]; } else { $image_width = __( '' , 'text_domain' ); }
     45            if ( isset( $instance[ 'image_height' ] ) ) { $image_height = $instance[ 'image_height' ]; } else { $image_height = __( '' , 'text_domain' ); }
     46           
     47            if ( isset( $instance[ 'post_type' ] ) ) { $post_type = $instance[ 'post_type' ]; } else { $post_type = __( 'post' , 'text_domain' ); }
     48            if ( isset( $instance[ 'custom_post_type' ] ) ) { $custom_post_type = $instance[ 'custom_post_type' ]; } else { $custom_post_type = __( '' , 'text_domain' ); }
     49           
     50            if ( isset( $instance[ 'show_support_link' ] ) ) { $show_support_link = $instance[ 'show_support_link' ]; } else { $show_support_link = __( 'checked' , 'text_domain' ); }
     51           
     52            $post_type_id = $this->get_field_id( 'post_type' );
     53            ?>
     54       
     55            <p>
     56                <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title :' ); ?></label>
     57                <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" style="width:192px;"/>
     58            </p>
     59
     60            <p>
     61                <label for="<?php echo $this->get_field_id( 'post_type' ); ?>"> <?php _e( 'Post Type :' ); ?> </label>
     62                <select id="<?php echo $this->get_field_id( 'post_type' ); ?>" name="<?php echo $this->get_field_name( 'post_type' ); ?>" onchange="showOps(this)" class="post_type_option" style="width: 161px;"> 
     63                    <option value="post" <? if ( $post_type == "post" ) { echo 'selected="selected"'; } ?> >Post</option>
     64                    <option value="custom" <? if ( $post_type == "custom" ) { echo 'selected="selected"'; } ?> >Custom Post Type</option>
     65                </select>
     66            </p>
     67            <p id="<?php echo $this->get_field_id( 'post_type' ); ?>_id"  <?php if ( $post_type != "custom") { echo 'style="display:none;"'; } ?> class="hidden_options">
     68                <label for="<?php echo $this->get_field_id( 'custom_post_type' ); ?>"><?php _e( 'Custom Post Type:' ); ?></label>
     69                <input id="<?php echo $this->get_field_id( 'custom_post_type' ); ?>" name="<?php echo $this->get_field_name( 'custom_post_type' ); ?>" type="text" value="<?php echo esc_attr( $custom_post_type); ?>" style="width:225px;" />
     70            </p>
     71
     72            <p>
     73                <label for="<?php echo $this->get_field_id( 'show_post_limit' ); ?>"><?php _e( 'Show How Many Posts:' ); ?></label>
     74                <input class="widefat" id="<?php echo $this->get_field_id( 'show_post_limit' ); ?>" name="<?php echo $this->get_field_name( 'show_post_limit' ); ?>" type="text" value="<?php echo esc_attr( $show_post_limit ); ?>" maxlength="2" style="text-align:center;width:95px;" />
     75            </p>
     76
     77            <p>
     78                <label for="<?php echo $this->get_field_id('order_post'); ?>"><?php _e('Order Posts:'); ?></label>
     79                <select id="<?php echo $this->get_field_id( 'order_post' ); ?>" name="<?php echo $this->get_field_name( 'order_post' ); ?>" style="width:154px;" >
     80                    <option value="ASC" <?php if ( $order_post == "ASC" ) { echo 'selected="selected"'; } ?>>Oldest to Newest</option>
     81                    <option value="DESC" <?php if ( $order_post == "DESC" ) { echo 'selected="selected"'; } ?>>Newest to Oldest</option>
     82                </select>
     83            </p>
     84
     85            <p>
     86                <label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Category :' ); ?></label>
     87                <select id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>" style="width:165px;" >
     88                    <option value="none">All</option>
     89                    <?php
     90                        $categories_list = get_categories();
     91                        foreach ($categories_list as $list_category ) {
     92
     93                            if ( $list_category->cat_ID == $category ) {
     94                                $selected = 'selected="selected"';
     95                            } else {
     96                                $selected = '';
     97                            }
     98
     99                            echo '<option value="'.$list_category->cat_ID.'" '. selected($list_category->cat_ID, $instance['category']).'>'. $list_category->cat_name.'</option>';
     100                        }
     101                    ?>
     102                </select>
     103            </p>
     104
     105            <p style="text-align:right;">
     106                <label for="<?php echo $this->get_field_id( 'show_post_title' ); ?>"><?php _e( 'Show The Post\'s Title :' ); ?></label>
     107                <input id="<?php echo $this->get_field_id( 'show_post_title' ); ?>" name="<?php echo $this->get_field_name( 'show_post_title' ); ?>" type="checkbox" value="<?php echo esc_attr( $show_post_title ); ?>" <?php checked( (bool) $show_post_title, true ); ?> onchange="showLinktitle(this)" />
     108            </p>
     109
     110            <p id="<?php echo $this->get_field_id( 'show_post_title' ); ?>_id"  style="text-align:right;<?php if ( $show_post_title == false ) { echo 'display:none;'; } ?>" class="hidden_options">
     111                <label for="<?php echo $this->get_field_id( 'link_title_to_cat' ); ?>"><?php _e( 'Link Title To Category :' ); ?></label>
     112                <input id="<?php echo $this->get_field_id( 'link_title_to_cat' ); ?>" name="<?php echo $this->get_field_name( 'link_title_to_cat' ); ?>" type="checkbox" value="<?php echo esc_attr( $link_title_to_cat ); ?>" <?php checked( (bool) $link_title_to_cat, true ); ?> />
     113            </p>
     114
     115            <p style="text-align:right;">
     116                <label for="<?php echo $this->get_field_id( 'show_featured_image' ); ?>"><?php _e( 'Show Featured Image :' ); ?></label>
     117                <input id="<?php echo $this->get_field_id( 'show_featured_image' ); ?>" name="<?php echo $this->get_field_name( 'show_featured_image' ); ?>" type="checkbox" value="<?php echo esc_attr( $show_featured_image ); ?>" <?php checked( (bool) $show_featured_image, true ); ?> onchange="showFeaturedImageOps(this)"/>
     118            </p>
     119
     120            <p <?php if ( $show_featured_image == false ) { echo 'style="display:none;"'; } ?> class="hidden_options">
     121                <label for="<?php echo $this->get_field_id( 'image_align' ); ?>"><?php _e( 'Align Image :' ); ?></label>
     122                <select id="<?php echo $this->get_field_id( 'image_align' ); ?>" name="<?php echo $this->get_field_name( 'image_align' ); ?>" style="width:150px;">
     123                    <option value="left" <? if ( $image_align == "left" ) { echo 'selected="selected"'; } ?>  style="text-align:left;">Left</option>
     124                    <option value="center" <? if ( $image_align == "center" ) { echo 'selected="selected"'; }  ?>   style="text-align:center;">Center</option>
     125                    <option value="right" <? if ( $image_align == "right" ) { echo 'selected="selected"'; }  ?>  style="text-align:right;" >Right</option>
     126                </select>
     127            </p>
     128
     129            <p <?php if ( $show_featured_image == false ) { echo 'style="display:none;"'; } ?> class="hidden_options">
     130                <label for="<?php echo $this->get_field_id( 'image_size' ); ?>"><?php _e( 'Image Size :' ); ?></label>
     131                <select id="<?php echo $this->get_field_id( 'image_size' ); ?>" name="<?php echo $this->get_field_name( 'image_size' ); ?>" class="image_size_options" onchange="showOps(this)" style="width:154px;">   
     132                    <option value="custom" <? if ( $image_size == "custom" ) { echo 'selected="selected"'; } ?>  >Custom</option>
     133                    <option value="thumbnail" <? if ( $image_size == "thumbnail" ) { echo 'selected="selected"'; } ?> >Thumbnail</option>
     134                    <option value="medium" <? if ( $image_size == "medium" ) { echo 'selected="selected"'; } ?> >Medium</option>
     135                    <option value="large" <? if ( $image_size == "large" ) { echo 'selected="selected"'; } ?> >Large</option>
     136                    <option value="full" <? if ( $image_size == "full" ) { echo 'selected="selected"'; } ?> >Full</option>
     137                </select>
     138            </p>
     139
     140            <p id="<?php echo $this->get_field_id( 'image_size' ); ?>_id" <?php if ( $image_size != "custom") { echo 'style="display:none;"'; } ?> class="hidden_options">
     141                <label for="<?php echo $this->get_field_id( 'image_width' ); ?>"><?php _e( 'Width :' ); ?></label>
     142                <input id="<?php echo $this->get_field_id( 'image_width' ); ?>" name="<?php echo $this->get_field_name( 'image_width' ); ?>" type="text" value="<?php echo esc_attr( $image_width ); ?>" <?php checked( (bool) $image_width, true ); ?> style="width:65px;text-align:center;" />
     143                <label for="<?php echo $this->get_field_id( 'image_height' ); ?>"><?php _e( 'Height :' ); ?></label>
     144                <input id="<?php echo $this->get_field_id( 'image_height' ); ?>" name="<?php echo $this->get_field_name( 'image_height' ); ?>" type="text" value="<?php echo esc_attr( $image_height ); ?>" <?php checked( (bool) $image_height, true ); ?> style="width:69px; text-align:center;" />
     145            </p>
     146
     147            <p style="text-align:right;">
     148                <label for="<?php echo $this->get_field_id( 'show_support_link' ); ?>"><?php _e( 'Show Support Link :' ); ?></label>
     149                <input id="<?php echo $this->get_field_id( 'show_support_link' ); ?>" name="<?php echo $this->get_field_name( 'show_support_link' ); ?>" type="checkbox" value="<?php echo esc_attr( $show_support_link ); ?>" <?php checked( (bool) $show_support_link, true ); ?> />
     150            </p>
     151
     152            <p style="text-align:right;">
     153                <a href="http://www.cssboss.com" target="_blank">CSSBoss.com</a> - <a href="http://www.youtube.com/subscription_center?add_user=thecssboss" target="_blank">Youtube</a> - <a href="http://csss.boss.com/donate" target="_blank">Donate</a> <strong>&#9774;</strong>
     154            </p>
     155            <?php
     156           
     157        }
     158
     159        public function widget($args, $instance)
     160        {
     161            // let's save the post data for after the widget.
     162            global $post;
     163            $post_old = $post;
     164
     165            extract( $args );   // grabbing all the args for the widget
     166
     167            // setting all the args for the widget
     168            $title = apply_filters( 'widget_title', $instance['title'] );
     169           
     170            // I hate when I can't select to display posts from ALL categories if I want to... so here you go :)
     171            if ( $instance['category'] != "none" ) {
     172                $category = '&cat='.$instance['category'];
     173            } else {
     174                $category = '';
     175            }
     176
     177            $post_type              = $instance['post_type'];
     178            $custom_post_type       = $instance['custom_post_type'];
     179            $order_post             = $instance['order_post'];
     180            $link_title_to_cat      = $instance['link_title_to_cat'];
     181            $show_post_title        = $instance['show_post_title'];
     182            $show_post_limit        = $instance['show_post_limit'];
     183            $show_featured_image    = $instance['show_featured_image'];
     184            $show_support_link      = $instance['show_support_link'];
     185            $image_size             = $instance['image_size'];
     186            $image_align            = $instance['image_align'];
     187
     188            // build the size variable to use with wp_query
     189            if ( $image_size == "custom" ) {
     190                $image_width = $instance['image_width'];
     191                $image_height = $instance['image_height'];
     192                $size = array( $image_width, $image_height );
     193            } else {
     194                $size = $image_size;
     195            }
     196
     197            // start the widget
     198            echo $before_widget;
     199
     200            // Let's build the title of the widget
     201            if ( $link_title_to_cat ) {
     202                echo $before_title . '<a href="' . get_category_link($category) . '">'.$title.'</a>'.$after_title;
     203            } else {
     204                echo $before_title . $title . $after_title;
     205            }
     206
     207            // some post type checks real quick
     208            if ($post_type == "custom" ) {
     209                $post_type = $custom_post_type;
     210            }
     211
     212            echo "<ul>"; // thanks Dan ;)
     213
     214            // this is where all the magic happens.
     215            $ak_featured_posts_query = new WP_Query( $category.'&showposts='.$show_post_limit.'&order='.$order_post.'&post_type='.$post_type ); // get new post data
     216
     217            while ( $ak_featured_posts_query->have_posts() ) : $ak_featured_posts_query->the_post();
     218                $image_title = get_the_title();  // The alt text for the featured image
     219                ?>
     220                    <li>
     221                        <a href="<?php the_permalink(); ?>">
     222                            <?php
     223                                if ($show_post_title) // To show the title of the post, or not...
     224                                {
     225                                    the_title();
     226                                }
     227
     228                                if ( $show_featured_image )
     229                                {
     230                                    if ( has_post_thumbnail() )
     231                                    {
     232                                        echo '<br />';
     233                                        the_post_thumbnail($size,
     234                                            array(
     235                                                'class' => 'ak_featured_post_image align'.$image_align.' ',
     236                                                'title' => $image_title
     237                                            )
     238                                        );
     239                                    }
     240                                }
     241                            ?>
     242                        </a>
     243                    </li>
     244                <?php
     245            endwhile;
     246
     247            echo "</ul>";
     248
     249            if ( $show_support_link )
     250            {
     251                echo '<p>Powered By <a href="http://www.cssboss.com/featured_post" target="_blank">AK: Featured Post</a></p>';
     252            }
     253
     254            echo $after_widget; // end widget
     255
     256            $post = $post_old; // finally, restoring the original post data, as if we never even touched it ;)
     257        }
     258       
     259        //fun stuff is over
    29260        public function __construct()
    30261        {
     
    46277                'id_base'=>'ak-featured-post' // base of id of li element ex. id="example-widget-1"
    47278            );
    48             $this->WP_Widget('ak_featured_post', 'AK: Featured Post', $widget_ops, $control_ops); // "Example Widget" will be name in control panel
     279            $this->WP_Widget( 'ak_featured_post', 'AK: Featured Post', $widget_ops, $control_ops ); // "Example Widget" will be name in control panel
    49280        }
    50281       
    51         public function form($instance)
    52         {
    53             if (isset($instance['category'])){ $category = $instance[ 'category' ]; } else { $category = __( 'Featured', 'text_domain' ); }
    54             if (isset($instance['title'])){ $title = $instance['title']; } else { $title = __('Featured Post','text_domain'); }
    55             if (isset($instance['link_title_to_cat'])){ $link_title_to_cat = $instance['link_title_to_cat']; } else { $link_title_to_cat = __('checked','text_domain'); }
    56             if (isset($instance['show_post_title'])){ $show_post_title = $instance['show_post_title']; } else { $show_post_title = __('checked','text_domain'); }
    57             if (isset($instance['show_post_limit'])){ $show_post_limit = $instance['show_post_limit']; } else { $show_post_limit = __('1','text_domain'); }
    58             if (isset($instance['show_featured_image'])){ $show_featured_image = $instance['show_featured_image']; } else { $show_featured_image = __('checked','text_domain'); }
    59             if (isset($instance['show_support_link'])){ $show_support_link = $instance['show_support_link']; } else { $show_support_link = __('checked','text_domain'); }
    60             if (isset($instance['order_post'])){ $order_post = $instance['order_post']; } else { $order_post = __('DESC','text_domain'); }
    61            
    62             ?>
    63             <p>
    64                 <label for="<?php echo $this->get_field_id( 'show_post_limit' ); ?>"><?php _e( 'Show How Many Posts:' ); ?></label>
    65                 <input class="widefat" id="<?php echo $this->get_field_id( 'show_post_limit' ); ?>" name="<?php echo $this->get_field_name( 'show_post_limit' ); ?>" type="text" value="<?php echo esc_attr( $show_post_limit ); ?>" maxlength="2" style="width: 25px;" />
    66             </p>
    67             <p>
    68                 <label for="<?php echo $this->get_field_id('order_post'); ?>"><?php _e('Order Posts:'); ?></label>
    69                 <select id="<?php echo $this->get_field_id( 'order_post' ); ?>" name="<?php echo $this->get_field_name( 'order_post' ); ?>" >
    70                     <option value="ASC" <?php if ( $order_post == "ASC" ) { echo 'selected="selected"'; } ?>>Oldest to Newest</option>
    71                     <option value="DESC" <?php if ( $order_post == "DESC" ) { echo 'selected="selected"'; } ?>>Newest to Oldest</option>
    72                 </select>
    73             </p>
    74             <p>
    75                 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    76                 <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
    77             </p>
    78            
    79             <p>
    80                 <label for="<?php echo $this->get_field_id( 'link_title_to_cat' ); ?>"><?php _e( 'Link Title To Category :' ); ?></label>
    81                 <input id="<?php echo $this->get_field_id( 'link_title_to_cat' ); ?>" name="<?php echo $this->get_field_name( 'link_title_to_cat' ); ?>" type="checkbox" value="<?php echo esc_attr( $link_title_to_cat ); ?>" <?php checked( (bool) $link_title_to_cat, true ); ?> />
    82             </p>
    83            
    84             <p>
    85                 <label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Category :' ); ?></label>
    86                 <select id="<?php echo $this->get_field_id( 'catgeory' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>" >
    87                     <?php
    88                         $categories_list = get_categories();
    89                         foreach ($categories_list as $list_category ) {
    90                            
    91                             if ( $list_category->cat_ID == $category ) {
    92                                 $selected = 'selected="selected"';
    93                             } else {
    94                                 $selected = '';
    95                             }
    96                            
    97                             echo '<option value="'.$list_category->cat_ID.'" '. selected($list_category->cat_ID, $instance['category']).'>'. $list_category->cat_name.'</option>';
    98                         }
    99                     ?>
    100                 </select>
    101             </p>
    102            
    103             <p>
    104                 <label for="<?php echo $this->get_field_id( 'show_post_title' ); ?>"><?php _e( 'Show Post Title :' ); ?></label>
    105                 <input id="<?php echo $this->get_field_id( 'show_post_title' ); ?>" name="<?php echo $this->get_field_name( 'show_post_title' ); ?>" type="checkbox" value="<?php echo esc_attr( $show_post_title ); ?>" <?php checked( (bool) $show_post_title, true ); ?> />
    106             </p>
    107            
    108             <p>
    109                 <label for="<?php echo $this->get_field_id( 'show_featured_image' ); ?>"><?php _e( 'Show Featured Image :' ); ?></label>
    110                 <input id="<?php echo $this->get_field_id( 'show_featured_image' ); ?>" name="<?php echo $this->get_field_name( 'show_featured_image' ); ?>" type="checkbox" value="<?php echo esc_attr( $show_featured_image ); ?>" <?php checked( (bool) $show_featured_image, true ); ?> />
    111             </p>
    112            
    113             <p>
    114                 <label for="<?php echo $this->get_field_id( 'show_support_link' ); ?>"><?php _e( 'Show Support Link :' ); ?></label>
    115                 <input id="<?php echo $this->get_field_id( 'show_support_link' ); ?>" name="<?php echo $this->get_field_name( 'show_support_link' ); ?>" type="checkbox" value="<?php echo esc_attr( $show_support_link ); ?>" <?php checked( (bool) $show_support_link, true ); ?> />
    116             </p>
    117             <p><a href="http://csss.boss.com/donate">Donate</a> - <a href="http://www.cssboss.com">CSSBoss.com</a></p>
    118             <?php
    119         }
    120        
    121         public function update($new_instance, $old_instance)
     282        public function update( $new_instance, $old_instance )
    122283        {
    123284            // save the widget info
    124285            $instance = array();
    125             $instance['show_post_limit'] = strip_tags( $new_instance['show_post_limit'] );
    126             $instance['order_post'] = strip_tags( $new_instance['order_post']);
    127             $instance['category'] = strip_tags( $new_instance['category'] );
    128             $instance['link_title_to_cat'] = ( isset( $new_instance['link_title_to_cat'] ) ? 1 : 0 );
    129             $instance['title'] = strip_tags( $new_instance['title']);
    130             $instance['show_post_title'] =  ( isset( $new_instance['show_post_title'] ) ? 1 : 0 );
    131             $instance['show_featured_image'] =  ( isset( $new_instance['show_featured_image'] ) ? 1 : 0 );
    132             $instance['show_support_link'] =  ( isset( $new_instance['show_support_link'] ) ? 1 : 0 );
     286            $instance['show_post_limit']     = strip_tags( $new_instance['show_post_limit'] );
     287            $instance['order_post']          = strip_tags( $new_instance['order_post'] );
     288            $instance['post_type']           = strip_tags( $new_instance['post_type'] );
     289            $instance['custom_post_type']    = strip_tags( $new_instance['custom_post_type'] );
     290            $instance['category']            = strip_tags( $new_instance['category'] );
     291            $instance['title']               = strip_tags( $new_instance['title'] );
     292            $instance['image_align']         = strip_tags( $new_instance['image_align'] );
     293            $instance['image_size']          = strip_tags( $new_instance['image_size'] );
     294            $instance['image_width']         = strip_tags( $new_instance['image_width'] );
     295            $instance['image_height']        = strip_tags( $new_instance['image_height'] );
     296            $instance['link_title_to_cat']   = ( isset( $new_instance['link_title_to_cat'] ) ? 1 : 0 );
     297            $instance['show_post_title']     = ( isset( $new_instance['show_post_title'] ) ? 1 : 0 );
     298            $instance['show_featured_image'] = ( isset( $new_instance['show_featured_image'] ) ? 1 : 0 );
     299            $instance['show_support_link']   = ( isset( $new_instance['show_support_link'] ) ? 1 : 0 );
    133300            return $instance;
    134301        }
    135        
    136         public function widget($args, $instance)
    137         {
    138             // let's save the post data for after the widget.
    139             global $post;
    140             $post_old = $post;
    141            
    142             extract( $args );   // grabbing all the args for the widget
    143 
    144             // setting all the args for the widget
    145             $title = apply_filters( 'widget_title', $instance['title'] );
    146             $category = $instance['category'];
    147             $order_post = $instance['order_post'];
    148             $link_title_to_cat = $instance['link_title_to_cat'];
    149             $show_post_title = $instance['show_post_title'];
    150             $show_post_limit = $instance['show_post_limit'];
    151             $show_featured_image = $instance['show_featured_image'];
    152             $show_support_link = $instance['show_support_link'];
    153            
    154             // start the widget
    155             echo $before_widget;                   
    156            
    157             // Let's build the title of the widget
    158             if ( $link_title_to_cat ) {
    159                 echo $before_title . '<a href="' . get_category_link($category) . '">'.$title.'</a>'.$after_title;
    160             } else {
    161                 echo $before_title . $title . $after_title;
    162             }
    163            
    164             echo "<ul>"; // thanks Dan ;)
    165            
    166             $ak_featured_posts_query = new WP_Query( 'cat='.$category.'&showposts='.$show_post_limit.'&order='.$order_post ); // get new post data
    167             while ( $ak_featured_posts_query->have_posts() ) : $ak_featured_posts_query->the_post();       
    168                 $image_title = get_the_title();  // The alt text for the featured image
    169                 ?>
    170                     <li>
    171                         <a href="<?php the_permalink(); ?>">
    172                             <?php
    173                                 if ($show_post_title) // To show the title of the post, or not... That is the question
    174                                 {
    175                                     the_title();
    176                                 }
    177                    
    178                                 if ( $show_featured_image )
    179                                 {
    180                                     if ( has_post_thumbnail() )
    181                                     {
    182                                         the_post_thumbnail('medium',
    183                                             array(
    184                                                 'class' => 'ak_featured_post_image',
    185                                                 'title' => $image_title
    186                                             )
    187                                         );
    188                                     }       
    189                                 }
    190                             ?>
    191                         </a>
    192                     </li>
    193                 <?php
    194              endwhile;
    195            
    196             echo "</ul>";
    197            
    198             if ( $show_support_link )
    199             {
    200                 echo 'Powered By <a href="http://www.cssboss.com/featured_post" target="_blank">AK: Featured Post</a>';
    201             }
    202            
    203             echo $after_widget; // end widget
    204             $post = $post_old; // finally, restoring the original post data, as if we never even touched it ;)
    205         }
    206302    }
     303   
     304    function ak_admin_js_enque($hook) {
     305        if( $hook == 'widgets.php' )
     306        wp_enqueue_script( 'my_custom_script', plugins_url('/akfp_admin_widget.js', __FILE__) , array( 'jquery' ) );
     307    }
     308    add_action( 'admin_enqueue_scripts', 'ak_admin_js_enque' );
    207309    add_action( 'widgets_init', create_function( '', 'register_widget( "ak_featured_post_widget" );' ) );
     310
    208311?>
  • akfeatured-post-widget/trunk/readme.txt

    r537752 r570953  
    11=== AK Featured Post Widget ===
    2 Contributors: Kaser
     2Contributors: Kaser, andrewSfreeman
    33Donate Link: http://www.cssboss.com/donate
    4 Tags: Featured Posts, Post Widget, Category Posts Widget, display posts
     4Tags: Featured Posts, Post Widget, Category Posts Widget, display posts, feature category posts, feature category, category widget, custom post type widget, featured custom post type, display custom post type
    55Requires at least: 3.3.1
    6 Tested up to: 3.3.2
    7 Stable tag: 1.5
     6Tested up to: 3.4.1
     7Stable tag: 1.6
    88
    9 A widget that you can use to display posts from a category
     9A widget that you can use to display posts!
    1010Watch This Video : http://www.youtube.com/watch?v=eWhafkO7uJQ
    1111
     
    1919* You can create custom titles
    2020* You can set how many posts you wish to display
     21* You can choose from Posts or Custom Post Types
    2122* You can select any category
    2223* You can choose wether or not to link the widget title to the category
    2324* You can choose wether or not to display the post title above the featured image
    24 * You can run as many instances of the widget that you want to!
     25* You can choose from predefined image sizes, or set custom width and height
     26* You can choose to align the featured image Left, Center or Right
     27* You can run as many instances of the widget that you want to!
     28
     29Known Bugs
     30* Fix the jQuery to work before having to save the widget
    2531
    2632== Installation ==
     
    4854= Once I install and activate the plugin, How do I use it? =
    4955
    50 This is only a widget, so you will need to drag and drop the widget into a sidebar or other widgetized area of your blog before you can configure it to work
     56This is only a widget, so you will need to drag and drop the widget into a sidebar or other widgetized area of your blog before you can configure it to work.
     57
     58= I dragged the widget over, but I can't set custom post types or image size, what do I do? =
     59
     60You will need to "save" the plugin so that you can fully configure the widget. Wordpress is weird sometimes.
     61
     62= How did you make such an awesome plugin? =
     63
     64Lots of reading.
    5165
    5266== Screenshots ==
    53 1. A Screen shot of the widget control options
    54 2. A Screen shot of the widget in use on cssboss.com
     671. A Screen shot of the widget control default options
     682. A Screen shot of the widget in use with default options
     693. A screen shot of some custom settings, with exposed custom fields
    5570
    5671== Change Log ==
     72
     73= 1.6 =
     74Now you can choose different sizes for the featured image or you can set custom dimensions
     75Added some javascript effects for a more stream lined experience.
     76Added custom post type support
     77Added ability to align image Left, Center or Right
    5778
    5879= 1.5 =
     
    84105
    85106== Upgrade Notice ==
     107= 1.6 =
     108Now compatible with custom post types, new responsive configuration design, set the size of the featured images, choose how to align the image, and cleaned up / organized code. Please upgrade today!! peace!
    86109
    87110= 1.5 =
Note: See TracChangeset for help on using the changeset viewer.