__( '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 '
$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', '