'amty_thumb', 'description' => __('Displays posts with thumbnail', 'amtyThumb_posts') ); /* Widget control settings. */ $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'amty-thumb-recent' ); /* Create the widget. */ $this->WP_Widget( 'amty-thumb-recent', __('Amty Thumb Posts', 'amtyThumb_posts'), $widget_ops, $control_ops ); } function update( $new_instance, $old_instance ) { $instance = $old_instance; /* Strip tags for title and width & Height to remove HTML (important for text inputs). */ $instance['title'] = strip_tags( $new_instance['title'] ); $instance['titlelen'] = strip_tags( $new_instance['titlelen'] ); $instance['maxpost'] = strip_tags( $new_instance['maxpost'] ); $instance['width'] = strip_tags( $new_instance['width'] ); $instance['height'] = strip_tags( $new_instance['height'] ); //$instance['show_default'] = $new_instance['show_default']; $instance['default_img_path'] = $new_instance['default_img_path']; $instance['pretag'] = $new_instance['pretag']; $instance['posttag'] = $new_instance['posttag']; $instance['template'] = $new_instance['template']; $instance['category'] = $new_instance['category']; $instance['widgettype'] = $new_instance['widgettype']; return $instance; } function form( $instance ) { /* Set up some default widget settings. */ $defaults = array( 'title' => 'Amty Thumb Recently Written', 'width' => '70', 'height' => '70', 'default_img_path' => '', 'pretag' => '', 'titlelen' => 50, 'maxpost' => 10, 'category' => 'All', 'widgettype' => 'Recently Written' ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>

Posts, Category :


id="get_field_id( 'show_default'); ?>" name="get_field_name( 'show_default'); ?>" />

*/?>


Template





Powered by article-stack & thinkzarahatke. 'Amty Thumb Posts', //'' to hide it 'before_title' => '

', 'after_title' => '

', 'thumb_width' => '70', 'thumb_height' => '70', 'default_img_path' => '', 'pretag' => '', 'template' => '', 'posttag' => '', 'title_len' => 30, 'max_post' => 10, 'category' => 'All', 'widgettype' => 'Recently Written' //'Recent','Random','Most Commented' ), $attr ) ); displayPosts($before_title, $after_title,$title, $thumb_width,$thumb_height,$max_post,$default_img_path,$pretag,$template,$posttag,$title_len,$category,$widgettype); } function displayPosts($before_title, $after_title, $title = '',$width = 70,$height = 70 ,$maxpost = 10 ,$default_img_path = '',$pretag = '',$template , $posttag = '',$titlelen = 30,$categoryName = 'All',$widgetType = 'Recent'){ global $wpdb; if ( $title != '' ){ echo $before_title . $title . $after_title; } if ($categoryName != 'All') { $theCatId = get_cat_id($categoryName ); //$theCatId = $theCatId->term_id; $category = "cat=" . $theCatId . "&"; }else{ $category = ''; } if($widgetType == 'Recently Written') $amty_posts = get_posts($category . "showposts=" . $maxpost . "&orderby=date"); elseif($widgetType == 'Random') $amty_posts = get_posts($category . "showposts=" . $maxpost . "&orderby=rand"); elseif($widgetType == 'Most Commented') $amty_posts = get_posts($category . "showposts=" . $maxpost . "&orderby=comment_count"); elseif($widgetType == 'Most Viewed') $amty_posts = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND post_type = 'post' AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $maxpost"); elseif($widgetType == 'Least Viewed') $amty_posts = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND post_type = 'post' AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views ASC LIMIT $maxpost"); elseif($widgetType == 'Recently Viewed') get_recently_viewed_posts_with_thumbs($maxpost,$template); $temp = ""; if($amty_posts) { foreach ($amty_posts as $post) { $temp = $template; //Decorating Post title //$ptitle = get_the_title($post); $ptitle = $post->post_title; if($titlelen != 0) { if (strlen($ptitle)> $titlelen ) { $ptitle = substr($ptitle,0,$titlelen ) . "..."; } } //'
  • %POST_TITLE%
  • ' /* setup_postdata($post); the_title(); the_attachment_link($post->ID, false); the_excerpt(); OR $attachments = get_posts($args); if ($attachments) { foreach ( $attachments as $attachment ) { echo apply_filters( 'the_title' , $attachment->post_title ); the_attachment_link( $attachment->ID , false ); } } */ $post_views = get_post_meta($post->ID, 'views', true); $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp); $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars); $temp = str_replace("%POST_TITLE%", $ptitle, $temp); $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp); $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp); $temp = str_replace("%POST_URL%", get_permalink($post->ID), $temp); $temp = str_replace("%POST_DATE%", mysql2date('F j, Y', $post->post_date, false), $temp); $pos = strrpos($temp, "%POST_THUMB%"); if ($pos === false) { //Do nothing }else{ $imgpath = lead_img_thumb_post($width ,$height ,$default_img_path , $post->ID ); $temp = str_replace("%POST_THUMB%", $imgpath , $temp); } $output .= $temp; } $output = $pretag . $output . $posttag; echo $output; } ?>
    post_title . "\" title=\"" . $output->post_content . "\"" . $style . "/>"; return $img_url; }//function end //if(!function_exists('get_recently_viewed_posts')) { function get_recently_viewed_posts_with_thumbs( $max_shown = 10 , $template) { if ( $max_shown + 0 > 0 ); else $max_shown = 10; $recently_viewed_posts = recently_viewed_posts_cache_get(); if ( !$recently_viewed_posts && !is_array( $recently_viewed_posts ) ) return ""; $html = ""; $count = 0; $html .= ""; // run a WP_Query so that the get_permalinks and get_the_titles don't cause individual queries. if ( $max_shown > 5 ) { // guesstimate threshold foreach ( $recently_viewed_posts as $item ) if ( $item[1] != recently_viewed_posts_get_remote_IP() ) { $post_in[] = $item[0]; if ( ++$count == $max_shown ) break; // i've shown enough } new WP_Query( array( 'post__in' => $post_in, 'posts_per_page' => 10000 ) ); } $count = 0; foreach ( $recently_viewed_posts as $item ) { $pos_content = strrpos($temp, "%POST_CONTENT%"); $pos_excerpt = strrpos($temp, "%POST_EXCERPT%"); if ($pos_content === false && $pos_excerpt === false ) { //Do nothing }else{ global $wpdb; $post_data = $wpdb->get_results("SELECT post_content,post_excerpt FROM wp_posts WHERE id = $item[0]"); echo $post_data; $post_content = $post_data[0]->post_content; $post_excerpt = $post_data[0]->post_excerpt; } $post_views = get_post_meta($item[0], 'views', true); if ( $item[1] != recently_viewed_posts_get_remote_IP() ) { $search = array( "%VIEW_COUNT%", "%POST_THUMB%", "%POST_URL%", "%POST_TITLE%", "%POST_CONTENT%", "%POST_EXCERPT%", "%POST_LAST_VIEWED%" ); $replace = array( $post_views, lead_img_thumb_post($width ,$height ,$default_img_path , $item[0] ), get_permalink( $item[0] ), get_the_title( $item[0] ), $post_content, $post_excerpt, recently_viewed_posts_time_since( $item[2] ) ); $template = apply_filters( "recently_viewed_posts_entry_format", $template, $item ); $entry = str_replace( $search, $replace, $template ); $html .= apply_filters( "recently_viewed_posts_entry", $entry ); if ( ++$count == $max_shown ) break; // i've shown enough } } return apply_filters( "get_recently_viewed_posts", $html ); } //} ?>