'sumakweb_widget_post','description' => __('Show a post/page/whatever as a widget','sumakweb')); $this->WP_Widget($widget_id,__('SumakWeb Featured post','sumakweb'),$widget_ops); } function widget($args,$instance) { extract($args); echo $before_widget; $title = ''; if (!empty($instance['title'])) { $title = $before_title . apply_filters('widget_title',$instance['title']) . $after_title; } echo $this->getPost($title,$instance['post_url']); echo $after_widget; } function update($new_instance,$old_instance) { $instance = $old_instance; $instance['title' ] = strip_tags($new_instance['title' ]); $instance['post_url'] = strip_tags($new_instance['post_url']); return $instance; } function form($instance) { $defaults = array('title' => __('Featured Post','sumakweb') ,'post_url' => '' ); $instance = wp_parse_args((array)$instance,$defaults); echo '

' . '' . '' . '

' . '

' . '' . '' . '

' ; } function getPost($title,$url) { // Originally from http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/formatting.php - function wp_trim_excerpt($text = '') $id = url_to_postid($url); if ($id) { $post = get_post($id); if ($post) { $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',array('class' => "attachment-thumbnail alignleft")); $excerpt = $post->post_content; $excerpt = strip_shortcodes($excerpt); //$excerpt = apply_filters('the_content',$excerpt); //$excerpt = str_replace(']]>',']]>',$excerpt); $excerpt_length = apply_filters('excerpt_length',55); $excerpt_more = apply_filters('excerpt_more',' ' . '[...]'); $excerpt = wp_trim_words($excerpt,$excerpt_length); return $title . '

' . $post->post_title . '

' . $thumbnail . apply_filters('wp_trim_excerpt',$excerpt) . '
' ; } } return $title; } }