'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['contentlength'] = strip_tags( $new_instance['contentlength'] );//contentlength
$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' => 30,
'contentlength' => 200,
'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,
'contentlength' => 200,
'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,$contentlength,$category,$widgettype);
}
function displayPosts($before_title, $after_title, $title = '',$width = 70,$height = 70 ,$maxpost = 10 ,$default_img_path = '',$pretag = '',$template , $posttag = '',$titlelen = 30,$contentlength=200,$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 = get_posts($category . "showposts=" . $maxpost . "&meta_key=amtyviewcount&orderby=meta_value_num&order=DESC");
elseif($widgetType == 'Least Viewed')
$amty_posts = get_posts($category . "showposts=" . $maxpost . "&meta_key=amtyviewcount&orderby=meta_value_num&order=ASC");
elseif($widgetType == 'Recently Viewed')
$amty_posts = get_posts($category . "showposts=" . $maxpost . "&meta_key=amtylastviewed&orderby=meta_value_num&order=DESC");
elseif($widgetType == 'Historical')
$amty_posts = get_posts($category . "showposts=" . $maxpost . "&meta_key=amtylastviewed&orderby=meta_value_num&order=ASC");
$temp = "";
if($amty_posts) {
foreach ($amty_posts as $post) {
$temp = $template;
//echo $temp;
//Decorating Post title
//$ptitle = get_the_title($post);
$ptitle = $post->post_title;
if($titlelen != 0)
{
if (strlen($ptitle)> $titlelen )
{
$stitle = substr($ptitle,0,$titlelen );
}
else{
$stitle = $ptitle;
}
}
//'
%POST_TITLE%'
$post_views = get_post_meta($post->ID, 'amtyviewcount', true);
//$amtylastviewed = get_post_meta($post->ID, 'amtylastviewed', true);
//$lastviewddate = "viewed at " . date($dataformat, $stamp);
$comments_count = $post->comment_count;
if(strrpos($temp, "%POST_AUTHOR%")){
$temp = str_replace("%POST_AUTHOR%", $author, $temp);
$author = get_the_author_meta("display_name",$post->post_author);
}
$temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp);
$temp = str_replace("%COMMENTS_COUNT%", $comments_count, $temp);
//$temp = str_replace("%POST_LAST_VIEWED%", $amtylastviewed, $temp);
$temp = str_replace("%POST_TITLE%", $ptitle, $temp);
$temp = str_replace("%SHORT_TITLE%", $stitle, $temp);
$temp = str_replace("%POST_EXCERPT%", $post->post_excerpt, $temp);
if(strrpos($temp, "%POST_CONTENT%")){
$strippedConetnts = getStrippedContent($post->post_content,$contentlength);
$temp = str_replace("%POST_CONTENT%",$strippedConetnts, $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 );
echo "
" . $imgpath;
//$temp = str_replace("%POST_THUMB%", $imgpath , $temp);
}
$output .= $temp;
}
$output = $pretag . $output . $posttag;
echo $output;
}
?>
ID,'views', true);
if($views){
add_post_meta($post->ID, "amtyviewcount", $views, true);
}else{
add_post_meta($post->ID, "amtyviewcount", 0, true);
}
}
}
}
add_action('the_content', 'amtyupdatemeta');
function amtyupdatemeta($content) {
if(is_single()){
//$content .= "";
$views = get_post_meta(get_the_ID(),'amtyviewcount', true);
update_post_meta(get_the_ID(), "amtyviewcount", $views + 1);
update_post_meta(get_the_ID(), "amtylastviewed", strtotime(date("m/d/Y h:i:s")));
}
return $content;
}
function amtyThumbPosts_admin() {
include('amtyThumbPostsAdminPg.php');
}
function amtyThumbPosts_admin_actions() {
add_options_page("amtyThumbPosts Options", "amtyThumbPosts Options", "activate_plugins", "amtyThumbPostsOptions", "amtyThumbPosts_admin");
}
add_action('admin_menu', 'amtyThumbPosts_admin_actions');
function getAmtyViewCount($pid){
return get_post_meta($pid,'views', true);
}
function getLastVisitedTime($pid){
$time = get_post_meta($pid,'amtylastviewed', true);
if($time > 0 )
return date("d-M-Y h:i:s",$time);
else
return '';
}
?>