__( 'Feature a page and display its excerpt and post thumbnail.', 'a-featured-page-widget' ) ) ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ function widget( $args, $instance ) { $cache = wp_cache_get( 'a_featured_page_widget', 'widget' ); if ( !is_array($cache) ) $cache = array(); if ( ! isset( $args['widget_id'] ) ) $args['widget_id'] = $this->id; if ( isset( $cache[ $args['widget_id'] ] ) ) { echo $cache[ $args['widget_id'] ]; return; } ob_start(); extract($args); if ( isset( $instance['page'] ) && $instance['page'] != -1 ) { $page_id = (int) $instance['page']; $page_link = strip_tags( $instance['page-link'] ); $image_size = $instance['image-size']; $p = new WP_Query( array( 'page_id' => $page_id ) ); if ( $p->have_posts() ) { $p->the_post(); $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? get_the_title() : $instance['title'], $instance, $this->id_base ); echo $before_widget; echo $before_title; echo $title; echo $after_title; ?>
flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset( $alloptions['a_featured_page_widget'] ) ) delete_option( 'a_featured_page_widget' ); return $instance; } function flush_widget_cache() { wp_cache_delete( 'a_featured_page_widget', 'widget' ); } function form( $instance ) { $title = isset( $instance['title'] ) ? strip_tags( $instance['title'] ) : ''; $page = isset( $instance['page'] ) ? (int) $instance['page'] : 0; $image_size = isset( $instance['image-size'] ) ? strip_tags( $instance['image-size'] ) : 'thumbnail'; $page_link = isset( $instance['page-link'] ) ? strip_tags( $instance['page-link'] ) : __( 'Continue reading', 'a-featured-page-widget' ); ?>
tag $args = array( 'depth' => 0, 'child_of' => 0, 'selected' => $page, 'name' => $this->get_field_name( 'page' ), 'id' => $this->get_field_id( 'page' ), 'show_option_none' => '', 'show_option_no_change' => '', 'option_none_value' => '' ); extract( $args, EXTR_SKIP ); $pages = get_pages($args); if ( ! empty( $pages ) ) : ?>