__('You can feature a certain post in this widget and display it, where and however you want, in your widget areas. A backup post can be given to avoid dubble content. Define, on what pages the widget will show.', self::language_file) ); $control_opts = array( 'width' => 400 ); parent::WP_Widget(false, $name = 'Advanced Featured Post', $widget_opts, $control_opts); self::$options = get_option('afpw_options'); } function form($instance) { // setup some default settings $defaults = array( 'title' => NULL, 'article' => NULL, 'backup' => NULL, 'id' => NULL, 'bid' => NULL, 'image' => NULL, 'width' => get_option('thumbnail_size_w'), 'headline' => NULL, 'h' => 3, 'excerpt' => NULL, 'linespace' => false, 'notext' => false, 'noshorts' => false, 'readmore' => false, 'rmtext' => NULL, 'thumb' => false, 'style' => NULL, 'homepage' => true, 'frontpage' => false, 'page' => false, 'category' => true, 'single' => false, 'date' => false, 'tag' => false, 'attachment' => false, 'taxonomy' => false, 'author' => false, 'search' => false, 'not_found' => false, 'class' => NULL, 'filter' => false, 'showcat' => NULL, 'showcat_txt'=> NULL, 'imgborder' => NULL, 'fullpost' => false, 'wordcount' => 3, 'words' => false ); $instance = wp_parse_args( $instance, $defaults ); $title = esc_attr($instance['title']); $thumb = esc_attr($instance['thumb']); $image = esc_attr($instance['image']); $article = esc_attr($instance['article']); $backup = esc_attr($instance['backup']); $width = esc_attr($instance['width']); $headline = esc_attr($instance['headline']); $excerpt = esc_attr($instance['excerpt']); $linespace = esc_attr($instance['linespace']); $notext = esc_attr($instance['notext']); $noshorts = esc_attr($instance['noshorts']); $readmore = esc_attr($instance['readmore']); $rmtext = esc_attr($instance['rmtext']); $style = esc_attr($instance['style']); $homepage=esc_attr($instance['homepage']); $frontpage=esc_attr($instance['frontpage']); $page=esc_attr($instance['page']); $category=esc_attr($instance['category']); $single=esc_attr($instance['single']); $date=esc_attr($instance['date']); $tag=esc_attr($instance['tag']); $attachment=esc_attr($instance['attachment']); $taxonomy=esc_attr($instance['taxonomy']); $author=esc_attr($instance['author']); $search=esc_attr($instance['search']); $not_found=esc_attr($instance['not_found']); $h=esc_attr($instance['h']); $class=esc_attr($instance['class']); $filter=esc_attr($instance['filter']); $id=esc_attr($instance['id']); $bid=esc_attr($instance['bid']); $showcat = esc_attr($instance['showcat']); $showcat_txt = esc_attr($instance['showcat_txt']); $imgborder = esc_attr($instance['imgborder']); $fullpost = esc_attr($instance['fullpost']); $wordcount = esc_attr($instance['wordcount']); $words = esc_attr($instance['words']); $args = array( 'posts_per_page' => -1, 'post_status' => 'publish' ); $features = get_posts($args); foreach ( $features as $feature ) : $posts[] = array($feature->ID, $feature->post_title ); endforeach; $base_id = 'widget-'.$this->id_base.'-'.$this->number.'-'; $base_name = 'widget-'.$this->id_base.'['.$this->number.']'; $pages = array ( array($base_id.'homepage', $base_name.'[homepage]', $homepage, __('Homepage', self::language_file)), array($base_id.'frontpage', $base_name.'[frontpage]', $frontpage, __('Frontpage (e.g. a static page as homepage)', self::language_file)), array($base_id.'page', $base_name.'[page]', $page, __('"Page" pages', self::language_file)), array($base_id.'category', $base_name.'[category]', $category, __('Category pages', self::language_file)), array($base_id.'single', $base_name.'[single]', $single, __('Single post pages', self::language_file)), array($base_id.'date', $base_name.'[date]', $date, __('Archive pages', self::language_file)), array($base_id.'tag', $base_name.'[tag]', $tag, __('Tag pages', self::language_file)), array($base_id.'attachment', $base_name.'[attachment]', $attachment, __('Attachments', self::language_file)), array($base_id.'taxonomy', $base_name.'[taxonomy]', $taxonomy, __('Custom Taxonomy pages (only available, if having a plugin)', self::language_file)), array($base_id.'author', $base_name.'[author]', $author, __('Author pages', self::language_file)), array($base_id.'search', $base_name.'[search]', $search, __('Search Results', self::language_file)), array($base_id.'not_found', $base_name.'[not_found]', $not_found, __('"Not Found"', self::language_file)) ); $checkall = array($base_id.'checkall', $base_name.'[checkall]', __('Check all', self::language_file)); $headings = array(array('1', 'h1'), array('2', 'h2'), array('3', 'h3'), array('4', 'h4'), array('5', 'h5'), array('6', 'h6')); $options = array (array('top', __('Above thumbnail', self::language_file)) , array('bottom', __('Under thumbnail', self::language_file)), array('none', __('Don't show title', self::language_file))); a5_text_field($base_id.'title', $base_name.'[title]', $title, __('Title:', self::language_file), array('space' => true, 'class' => 'widefat')); a5_select($base_id.'article', $base_name.'[article]', $posts, $article, __('Choose here the post, you want to appear in the widget.', self::language_file), __('Take a random post', self::language_file), array('space' => true, 'class' => 'widefat')); a5_select($base_id.'backup', $base_name.'[backup]',$posts, $backup, __('Choose here the backup post. It will appear, when a single post page shows the featured article.', self::language_file), __('Take a random post', self::language_file), array('space' => true, 'class' => 'widefat')); a5_number_field($base_id.'id', $base_name.'[id]', $id, __('Post ID (if you want a custom post type or simply don't want to use the dropdown menu):', self::language_file), array('space' => true, 'size' => 4, 'step' => 1)); a5_number_field($base_id.'bid', $base_name.'[bid]', $bid, __('ID for backup post (if you want a custom post type or simply you don't want to use the dropdown menu):', self::language_file), array('space' => true, 'size' => 4, 'step' => 1)); a5_checkbox($base_id.'showcat', $base_name.'[showcat]', $showcat, __('Check to show the categories in which the post is filed.', self::language_file), array('space' => true)); a5_text_field($base_id.'showcat_txt', $base_name.'[showcat_txt]', $showcat_txt, __('Give some text that you want in front of the post's categtories (i.e 'filed under':', self::language_file), array('space' => true, 'class' => 'widefat')); a5_checkbox($base_id.'image', $base_name.'[image]', $image, __('Check to get the first image of the post as thumbnail.', self::language_file), array('space' => true)); a5_number_field($base_id.'width', $base_name.'[width]', $width, __('Width of the thumbnail (in px):', self::language_file), array('space' => true, 'size' => 4, 'step' => 1)); a5_text_field($base_id.'imgborder', $base_name.'[imgborder]', $imgborder, sprintf(__('If wanting a border around the image, write the style here. %s would make it a black border, 1px wide.', self::language_file), '1px solid #000000'), array('space' => true, 'class' => 'widefat')); a5_checkbox($base_id.'thumb', $base_name.'[thumb]', $thumb, sprintf(__('Check to %snot%s display the thumbnail of the post.', self::language_file), '', ''), array('space' => true)); a5_select($base_id.'headline', $base_name.'[headline]', $options, $headline, __('Choose, whether or not to display the title and whether it comes above or under the thumbnail.', self::language_file), false, array('space' => true)); a5_select($base_id.'h', $base_name.'[h]', $headings, $h, __('Weight of the Post Title:', self::language_file), false, array('space' => true)); a5_textarea($base_id.'excerpt', $base_name.'[excerpt]', $excerpt, __('If the excerpt of the post is not defined, by default the first 3 sentences of the post are shown. You can enter your own excerpt here, if you want.', self::language_file), array('space' => true, 'class' => 'widefat', 'style' => 'height: 60px;')); a5_number_field($base_id.'wordcount', $base_name.'[wordcount]', $wordcount, __('In case there is no excerpt defined, how many sentences are displayed:', self::language_file), array('space' => true, 'size' => 4, 'step' => 1)); a5_checkbox($base_id.'words', $base_name.'[words]', $words, __('Check to display words instead of sentences.', self::language_file), array('space' => true)); a5_checkbox($base_id.'fullpost', $base_name.'[fullpost]', $image, __('Check to display the full post instead of an excerpt.', self::language_file), array('space' => true)); a5_checkbox($base_id.'linespace', $base_name.'[linespace]', $linespace, __('Check to have each sentence in a new line.', self::language_file), array('space' => true)); a5_checkbox($base_id.'notext', $base_name.'[notext]', $notext, sprintf(__('Check to %snot%s display the excerpt.', self::language_file), '', ''), array('space' => true)); a5_checkbox($base_id.'noshorts', $base_name.'[noshorts]', $noshorts, __('Check to suppress shortcodes in the widget (in case the content is showing).', self::language_file), array('space' => true)); a5_checkbox($base_id.'filter', $base_name.'[filter]', $filter, __('Check to return the excerpt unfiltered (might avoid interferences with other plugins).', self::language_file), array('space' => true)); a5_checkbox($base_id.'readmore', $base_name.'[readmore]', $readmore, __('Check to have an additional 'read more' link at the end of the excerpt.', self::language_file), array('space' => true)); a5_text_field($base_id.'rmtext', $base_name.'[rmtext]', $rmtext, sprintf(__('Write here some text for the 'read more' link. By default, it is %s:', self::language_file), '[…]'), array('space' => true, 'class' => 'widefat')); a5_text_field($base_id.'class', $base_name.'[class]', $class, __('If you want to style the 'read more' link, you can enter a class here.', self::language_file), array('space' => true, 'class' => 'widefat')); a5_checkgroup(false, false, $pages, __('Check, where you want to show the widget. By default, it is showing on the homepage and the category pages:', self::language_file), $checkall); if (empty(self::$options['css'])) a5_textarea($base_id.'style', $base_name.'[style]', $style, sprintf(__('Here you can finally style the widget. Simply type something like%1$s%2$sborder: 2px solid;%2$sborder-color: #cccccc;%2$spadding: 10px;%3$s%2$sto get just a gray outline and a padding of 10 px. If you leave that section empty, your theme will style the widget.', self::language_file), '', '
', '
'), array('space' => true, 'class' => 'widefat', 'style' => 'height: 60px;')); a5_resize_textarea(array($base_id.'excerpt', $base_id.'style'), true); } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['article'] = strip_tags($new_instance['article']); $instance['backup'] = strip_tags($new_instance['backup']); $instance['thumb'] = strip_tags($new_instance['thumb']); $instance['image'] = strip_tags($new_instance['image']); $instance['width'] = strip_tags($new_instance['width']); $instance['headline'] = strip_tags($new_instance['headline']); $instance['excerpt'] = strip_tags($new_instance['excerpt']); $instance['linespace'] = strip_tags($new_instance['linespace']); $instance['notext'] = strip_tags($new_instance['notext']); $instance['noshorts'] = strip_tags($new_instance['noshorts']); $instance['readmore'] = strip_tags($new_instance['readmore']); $instance['rmtext'] = strip_tags($new_instance['rmtext']); $instance['adsense'] = strip_tags($new_instance['adsense']); $instance['style'] = strip_tags($new_instance['style']); $instance['homepage'] = strip_tags($new_instance['homepage']); $instance['frontpage'] = strip_tags($new_instance['frontpage']); $instance['page'] = strip_tags($new_instance['page']); $instance['category'] = strip_tags($new_instance['category']); $instance['single'] = strip_tags($new_instance['single']); $instance['date'] = strip_tags($new_instance['date']); $instance['tag'] = strip_tags($new_instance['tag']); $instance['attachment'] = strip_tags($new_instance['attachment']); $instance['taxonomy'] = strip_tags($new_instance['taxonomy']); $instance['author'] = strip_tags($new_instance['author']); $instance['search'] = strip_tags($new_instance['search']); $instance['not_found'] = strip_tags($new_instance['not_found']); $instance['h'] = strip_tags($new_instance['h']); $instance['class'] = strip_tags($new_instance['class']); $instance['filter'] = strip_tags($new_instance['filter']); $instance['id'] = strip_tags($new_instance['id']); $instance['bid'] = strip_tags($new_instance['bid']); $instance['showcat'] = strip_tags($new_instance['showcat']); $instance['showcat_txt'] = strip_tags($new_instance['showcat_txt']); $instance['imgborder'] = strip_tags($new_instance['imgborder']); $instance['fullpost'] = strip_tags($new_instance['fullpost']); $instance['wordcount'] = strip_tags($new_instance['wordcount']); $instance['words'] = strip_tags($new_instance['words']); return $instance; } function widget($args, $instance) { // get the type of page, we're actually on if (is_front_page()) $afpw_pagetype='frontpage'; if (is_home()) $afpw_pagetype='homepage'; if (is_page()) $afpw_pagetype='page'; if (is_category()) $afpw_pagetype='category'; if (is_single()) $afpw_pagetype='single'; if (is_date()) $afpw_pagetype='date'; if (is_tag()) $afpw_pagetype='tag'; if (is_attachment()) $afpw_pagetype='attachment'; if (is_tax()) $afpw_pagetype='taxonomy'; if (is_author()) $afpw_pagetype='author'; if (is_search()) $afpw_pagetype='search'; if (is_404()) $afpw_pagetype='not_found'; // display only, if said so in the settings of the widget if ($instance[$afpw_pagetype]) : $eol = "\r\n"; // the widget is displayed extract( $args ); $title = apply_filters('widget_title', $instance['title']); if (!empty($instance['style'])) : $style=str_replace(array("\r\n", "\n", "\r"), '', $instance['style']); $before_widget = str_replace('>', 'style="'.$style.'">', $before_widget); endif; // widget starts echo $before_widget.$eol; if ( $title ) echo $before_title . $title . $after_title . $eol; global $wp_query; $article = ($instance['id']) ? $instance['id'] : $instance['article']; $backup = ($instance['bid']) ? $instance['bid'] : $instance['backup']; $afpw_post_id = get_post($article); $afpw_post_name = $afpw_post_id->post_name; $afpw_post = ($article == $wp_query->get( 'p' ) || $afpw_post_name == $wp_query->get ( 'name' )) ? 'post_type=any&p='.$backup : 'post_type=any&p='.$article; if ($afpw_post=='post_type=any&p=') $afpw_post = 'posts_per_page=1&orderby=rand'; /* This is the actual function of the plugin, it fills the widget with the customized post */ global $post; $afpw_posts = new WP_Query($afpw_post); while($afpw_posts->have_posts()) : $afpw_posts->the_post(); if ($instance['showcat']) : $post_byline = ($instance['showcat_txt']) ? $eol.'

'.$eol.$instance['showcat_txt'].' ' : $eol.'

'; echo $post_byline; the_category(', '); echo $eol.'

'.$eol; endif; $afpw_tags = A5_Image::tags(self::language_file); $afpw_image_alt = $afpw_tags['image_alt']; $afpw_image_title = $afpw_tags['image_title']; $afpw_title_tag = $afpw_tags['title_tag']; // headline, if wanted if ($instance['headline'] != 'none') : $afpw_options = get_option('afpw_options'); $afpw_headline = ''.$eol.''.get_the_title().''.$eol.''; endif; // thumbnail, if wanted if (!$instance['thumb']) : $afpw_imgborder = (!empty($instance['imgborder'])) ? ' style="border: '.$instance['imgborder'].';"' : ''; $id = get_the_ID(); $args = array ( 'id' => $id, 'option' => 'afpw_options', 'width' => $instance['width'] ); $afpw_image_info = A5_Image::thumbnail($args); $afpw_thumb = $afpw_image_info[0]; $afpw_width = $afpw_image_info[1]; $afpw_height = ($afpw_image_info[2]) ? ' height="'.$afpw_image_info[2].'"' :''; if ($afpw_thumb) if ($afpw_width) $afpw_img_tag = ''.$afpw_image_alt.''; if (!empty($afpw_img_tag)) $afpw_image = ''.$afpw_img_tag.''.$eol.'
'.$eol; endif; // excerpt if wanted if (!$instance['notext']) : $rmtext = ($instance['rmtext']) ? $instance['rmtext'] : '[…]'; $shortcode = ($instance['noshorts']) ? false : 1; $filter = ($instance['filter']) ? false : true; $args = array( 'usertext' => $instance['excerpt'], 'excerpt' => $post->post_excerpt, 'content' => $post->post_content, 'shortcode' => $shortcode, 'count' => $instance['wordcount'], 'linespace' => $instance['linespace'], 'link' => get_permalink(), 'title' => $afpw_title_tag, 'readmore' => $instance['readmore'], 'rmtext' => $rmtext, 'class' => $instance['class'], 'filter' => $filter ); if (!empty($instance['fullpost'])) $args['type'] = 'post'; if (!empty($instance['words'])) $args['type'] = 'words'; $afpw_text = A5_Excerpt::text($args); endif; // writing the stuff in the widget if ($instance['headline'] == 'top') echo $afpw_headline.$eol; if (!$instance['thumb'] && isset($afpw_image)) echo $afpw_image; if ($instance['headline'] == 'bottom') echo $afpw_headline.$eol; if (!$instance['notext']) echo do_shortcode($afpw_text).$eol; endwhile; // Restore original Query & Post Data wp_reset_query(); wp_reset_postdata(); echo $after_widget.$eol; else: echo ""; endif; } // widget } // Advanced Featured Post Widget add_action('widgets_init', create_function('', 'return register_widget("Advanced_Featured_Post_Widget");')); ?>