Changeset 533761
- Timestamp:
- 04/19/2012 11:26:59 PM (14 years ago)
- File:
-
- 1 edited
-
akfeatured-post-widget/trunk/ak_featured_post.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
akfeatured-post-widget/trunk/ak_featured_post.php
r533582 r533761 4 4 Plugin URI: http://cssboss.com/featured_post 5 5 Description: Plugin to display the latest post from a specific category 6 Version: 1 6 Version: 1.1 7 7 Author: Andrew Kaser 8 8 Author URI: http://www.andrewkaser.com … … 33 33 34 34 public function form($instance){ 35 if ( isset( $instance[ 'category' ] ) ) { 36 $category = $instance[ 'category' ]; 37 $title = $instance['title']; 38 $show_post_title = $instance['show_post_title']; 39 } 40 else { 41 $category = __( 'Featured', 'text_domain' ); 42 $title = __('Featured Post','text_domain'); 43 $show_post_title = __('checked','text_domain'); 44 } 35 if (isset($instance['category'])){ $category = $instance[ 'category' ]; } else { $category = __( 'Featured', 'text_domain' ); } 36 if (isset($instance['title'])){ $title=$instance['title']; } else { $title=__('Featured Post','text_domain'); } 37 if (isset($instance['link_title_to_cat'])){ $link_title_to_cat = $instance['link_title_to_cat']; } else { $link_title_to_cat = __('checked','text_domain'); } 38 if (isset($instance['show_post_title'])){ $show_post_title = $instance['show_post_title']; } else { $show_post_title = __('checked','text_domain'); } 39 if (isset($instance['show_post_limit'])){ $show_post_limit = $instance['show_post_limit']; } else { $show_post_limit = __('1','text_domain'); } 45 40 ?> 46 41 <p> 47 <label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Title:' ); ?></label> 48 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> 49 <label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Category:' ); ?></label> 50 <input class="widefat" id="<?php echo $this->get_field_id( 'catgeory' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>" type="text" value="<?php echo esc_attr( $category ); ?>" /> 51 <label for="<?php echo $this->get_field_id( 'show_post_title' ); ?>"><?php _e( 'Show Post Title:' ); ?></label> 52 <input class="widefat" 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 ); ?> /> 42 <label for="<?php echo $this->get_field_id( 'show_post_limit' ); ?>"><?php _e( 'Show How Many Posts:' ); ?></label> 43 <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;" /> 44 <br /> 45 46 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 47 <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 ); ?>" /> 48 49 <label for="<?php echo $this->get_field_id( 'link_title_to_cat' ); ?>"><?php _e( 'Link Title To Category :' ); ?></label> 50 <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 ); ?> /> 51 <br /> 52 <label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Category :' ); ?></label> 53 <select id="<?php echo $this->get_field_id( 'catgeory' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>" > 54 <?php 55 $categories_list = get_categories(); 56 foreach ($categories_list as $list_category ) { 57 58 if ( $list_category->cat_ID == $category ) { 59 $selected = 'selected="selected"'; 60 } else { 61 $selected = ''; 62 } 63 64 echo '<option value="'.$list_category->cat_ID.'" '. selected($list_category->cat_ID, $instance['category']).'>'. $list_category->cat_name.'</option>'; 65 } 66 ?> 67 </select> 68 <br /> 69 <label for="<?php echo $this->get_field_id( 'show_post_title' ); ?>"><?php _e( 'Show Post Title :' ); ?></label> 70 <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 ); ?> /> 71 53 72 </p> 54 73 <?php … … 58 77 // save the widget info 59 78 $instance = array(); 79 $instance['show_post_limit'] = strip_tags( $new_instance['show_post_limit'] ); 60 80 $instance['category'] = strip_tags( $new_instance['category'] ); 81 $instance['link_title_to_cat'] = ( isset( $new_instance['link_title_to_cat'] ) ? 1 : 0 ); 61 82 $instance['title'] = strip_tags( $new_instance['title']); 62 83 $instance['show_post_title'] = ( isset( $new_instance['show_post_title'] ) ? 1 : 0 ); … … 75 96 $title = apply_filters( 'widget_title', $instance['title'] ); 76 97 $category = $instance['category']; 98 $link_title_to_cat = $instance['link_title_to_cat']; 77 99 $show_post_title = $instance['show_post_title']; 100 $show_post_limit = $instance['show_post_limit']; 78 101 79 102 80 103 echo $before_widget; // start the widget 81 82 echo $before_title . $title . $after_title; // Widget Title, adding link functionality later83 84 $ak_featured_posts_query = new WP_Query( 'cat='.$category.'&showposts=1' ); // get new post data85 while ( $ak_featured_posts_query->have_posts() ) : $ak_featured_posts_query->the_post(); ?>86 104 87 <?php 105 // Let's build the title of the widget 106 if ( $link_title_to_cat ) { 107 echo $before_title . '<a href="' . get_category_link($category) . '">'.$title.'</a>'.$after_title; 108 } else { 109 echo $before_title . $title . $after_title; 110 } 111 112 $ak_featured_posts_query = new WP_Query( 'cat='.$category.'&showposts='.$show_post_limit ); // get new post data 113 while ( $ak_featured_posts_query->have_posts() ) : $ak_featured_posts_query->the_post(); 114 88 115 $image_title = get_the_title(); // The alt text for the featured image 89 ?> 90 <li><a href="<?php the_permalink(); ?>"> 91 <?php 92 if ($show_post_title) { the_title(); } // To show the title of the post, or not... That is the question 93 94 if (has_post_thumbnail()) { 95 the_post_thumbnail('medium', array( 96 'class' => 'ak_featured_post_image', 97 'title' => $image_title)); 98 } ?> 99 </a></li> 116 ?> 117 <li> 118 <a href="<?php the_permalink(); ?>"> 119 <?php 120 if ($show_post_title) { the_title(); } // To show the title of the post, or not... That is the question 121 122 if (has_post_thumbnail()) { 123 the_post_thumbnail('medium', array( 124 'class' => 'ak_featured_post_image', 125 'title' => $image_title)); 126 } 127 ?> 128 </a> 129 </li> 100 130 <?php 101 131 endwhile; … … 108 138 add_action( 'widgets_init', create_function( '', 'register_widget( "ak_featured_post_widget" );' ) ); 109 139 ?> 140
Note: See TracChangeset
for help on using the changeset viewer.