__( 'A Foo Widget', 'text_domain' ), ) // Args ); $this->defaults = array( 'title' => '', 'page_id' => '', 'show_image' => 0, 'image_alignment' => '', 'image_size' => '', 'show_title' => 0, 'show_byline' => 0, 'show_content' => 0, 'content_limit' => '', 'more_text' => '', ); $control_ops = array( 'width' => 200, 'height' => 250, ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { extract( $args ); /** Merge with defaults */ $instance = wp_parse_args( (array) $instance, $this->defaults ); echo $before_widget; /** Set up the author bio */ if ( ! empty( $instance['title'] ) ) echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title; $featured_page = new WP_Query( array( 'page_id' => $instance['page_id'] ) ); if ( $featured_page->have_posts() ) : while ( $featured_page->have_posts() ) : $featured_page->the_post(); echo '
'; if ( ! empty( $instance['show_image'] ) ) printf( '%s', get_permalink(), the_title_attribute( 'echo=0' ), esc_attr( $instance['image_alignment'] ), get_image( array( 'format' => 'html', 'size' => $instance['image_size'], ) ) ); if ( ! empty( $instance['show_title'] ) ) printf( '

%s

', get_permalink(), the_title_attribute( 'echo=0' ), get_the_title() ); if ( ! empty( $instance['show_byline'] ) ) { echo '

'; the_time( 'F j, Y' ); echo ' ' . __( 'by', 'text_domain' ) . ' '; the_author_posts_link(); echo g_ent( ' · ' ); comments_popup_link( __( 'Leave a Comment', 'text_domain' ), __( '1 Comment', 'text_domain' ), __( '% Comments', 'text_domain' ) ); echo ' '; edit_post_link( __( '(Edit)', 'text_domain' ), '', '' ); echo '

'; } if ( ! empty( $instance['show_content'] ) ) { if ( empty( $instance['content_limit'] ) ) the_content( $instance['more_text'] ); else the_content_limit( (int) $instance['content_limit'], esc_html( $instance['more_text'] ) ); } echo '
' . "\n\n"; endwhile; endif; echo $after_widget; wp_reset_query(); } /** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from database. * * @return array Updated safe values to be saved. */ function update( $new_instance, $old_instance ) { $new_instance['title'] = strip_tags( $new_instance['title'] ); $new_instance['more_text'] = strip_tags( $new_instance['more_text'] ); return $new_instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ function form( $instance ) { /** Merge with defaults */ $instance = wp_parse_args( (array) $instance, $this->defaults ); ?>

$this->get_field_name( 'page_id' ), 'selected' => $instance['page_id'] ) ); ?>


/>


/>

/>

/>

'html', 'size' => 'full', 'num' => 0, 'attr' => '', ); $defaults = apply_filters( 'get_image_default_args', $defaults ); $args = wp_parse_args( $args, $defaults ); /** Allow child theme to short-circuit this function */ $pre = apply_filters( 'pre_get_image', false, $args, $post ); if ( false !== $pre ) return $pre; /** Check for post image (native WP) */ if ( has_post_thumbnail() && ( 0 === $args['num'] ) ) { $id = get_post_thumbnail_id(); $html = wp_get_attachment_image( $id, $args['size'], false, $args['attr'] ); list( $url ) = wp_get_attachment_image_src( $id, $args['size'], false, $args['attr'] ); } /** Else pull the first (default) image attachment */ else { $id = get_image_id( $args['num'] ); $html = wp_get_attachment_image( $id, $args['size'], false, $args['attr'] ); list( $url ) = wp_get_attachment_image_src( $id, $args['size'], false, $args['attr'] ); } /** Source path, relative to the root */ $src = str_replace( home_url(), '', $url ); /** Determine output */ if ( 'html' === strtolower( $args['format'] ) ) $output = $html; elseif ( 'url' === strtolower( $args['format'] ) ) $output = $url; else $output = $src; // Return FALSE if $url is blank if ( empty( $url ) ) $output = false; /** Return FALSE if $src is invalid (file doesn't exist) */ // if ( ! file_exists( ABSPATH . $src ) ) // $output = false; /** Return data, filtered */ return apply_filters( 'get_image', $output, $args, $id, $html, $url, $src ); } function get_image_id( $index = 0 ) { global $post; $image_ids = array_keys( get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', ) ) ); if ( isset( $image_ids[$index] ) ) return $image_ids[$index]; return false; } function the_content_limit( $max_characters, $more_link_text = '(more...)', $stripteaser = false ) { $content = get_the_content_limit( $max_characters, $more_link_text, $stripteaser ); echo apply_filters( 'the_content_limit', $content ); } function get_the_content_limit( $max_characters, $more_link_text = '(more...)', $stripteaser = false ) { $content = get_the_content( '', $stripteaser ); /** Strip tags and shortcodes so the content truncation count is done correctly */ $content = strip_tags( strip_shortcodes( $content ), apply_filters( 'get_the_content_limit_allowedtags', '