'university_hub_widget_social', 'description' => __( 'Displays social icons.', 'university-hub' ), 'customize_selective_refresh' => true, ); $fields = array( 'title' => array( 'label' => __( 'Title:', 'university-hub' ), 'type' => 'text', 'class' => 'widefat', ), ); if ( false === has_nav_menu( 'social' ) ) { $fields['message'] = array( 'label' => __( 'Social menu is not set. Please create menu and assign it to Social Menu.', 'university-hub' ), 'type' => 'message', 'class' => 'widefat', ); } parent::__construct( 'university-hub-social', __( 'UH: Social', 'university-hub' ), $opts, array(), $fields ); } /** * Outputs the content for the current widget instance. * * @since 1.0.0 * * @param array $args Display arguments. * @param array $instance Settings for the current widget instance. */ function widget( $args, $instance ) { $params = $this->get_params( $instance ); echo $args['before_widget']; if ( ! empty( $params['title'] ) ) { echo $args['before_title'] . $params['title'] . $args['after_title']; } if ( has_nav_menu( 'social' ) ) { wp_nav_menu( array( 'theme_location' => 'social', 'container' => false, 'depth' => 1, 'link_before' => '', 'link_after' => '', ) ); } echo $args['after_widget']; } } endif; if ( ! class_exists( 'University_Hub_Featured_Page_Widget' ) ) : /** * Featured page widget Class. * * @since 1.0.0 */ class University_Hub_Featured_Page_Widget extends University_Hub_Widget_Base { /** * Sets up a new widget instance. * * @since 1.0.0 */ function __construct() { $opts = array( 'classname' => 'university_hub_widget_featured_page', 'description' => __( 'Displays single featured Page or Post.', 'university-hub' ), 'customize_selective_refresh' => true, ); $fields = array( 'title' => array( 'label' => __( 'Title:', 'university-hub' ), 'type' => 'text', 'class' => 'widefat', ), 'use_page_title' => array( 'label' => __( 'Use Page/Post Title as Widget Title', 'university-hub' ), 'type' => 'checkbox', 'default' => true, ), 'featured_page' => array( 'label' => __( 'Select Page:', 'university-hub' ), 'type' => 'dropdown-pages', 'show_option_none' => __( '— Select —', 'university-hub' ), ), 'id_message' => array( 'label' => '' . _x( 'OR', 'message', 'university-hub' ) . '', 'type' => 'message', ), 'featured_post' => array( 'label' => __( 'Post ID:', 'university-hub' ), 'placeholder' => __( 'Eg: 1234', 'university-hub' ), 'type' => 'text', 'sanitize_callback' => 'university_hub_widget_sanitize_post_id', ), 'content_type' => array( 'label' => __( 'Show Content:', 'university-hub' ), 'type' => 'select', 'default' => 'full', 'options' => array( 'excerpt' => __( 'Excerpt', 'university-hub' ), 'full' => __( 'Full', 'university-hub' ), ), ), 'excerpt_length' => array( 'label' => __( 'Excerpt Length:', 'university-hub' ), 'description' => __( 'Applies when Excerpt is selected in Content option.', 'university-hub' ), 'type' => 'number', 'css' => 'max-width:60px;', 'default' => 40, 'min' => 1, 'max' => 400, ), 'featured_image' => array( 'label' => __( 'Featured Image:', 'university-hub' ), 'type' => 'select', 'options' => university_hub_get_image_sizes_options(), ), 'featured_image_alignment' => array( 'label' => __( 'Image Alignment:', 'university-hub' ), 'type' => 'select', 'default' => 'center', 'options' => university_hub_get_image_alignment_options(), ), ); parent::__construct( 'university-hub-featured-page', __( 'UH: Featured Page', 'university-hub' ), $opts, array(), $fields ); } /** * Outputs the content for the current widget instance. * * @since 1.0.0 * * @param array $args Display arguments. * @param array $instance Settings for the current widget instance. */ function widget( $args, $instance ) { $params = $this->get_params( $instance ); // ID validation. $our_post_object = null; $our_id = ''; if ( absint( $params['featured_post'] ) > 0 ) { $our_id = absint( $params['featured_post'] ); } if ( absint( $params['featured_page'] ) > 0 ) { $our_id = absint( $params['featured_page'] ); } if ( absint( $our_id ) > 0 ) { $raw_object = get_post( $our_id ); if ( ! in_array( $raw_object->post_type, array( 'attachment', 'nav_menu_item', 'revision' ) ) ) { $our_post_object = $raw_object; } } if ( ! $our_post_object ) { // No valid object; bail now! return; } echo $args['before_widget']; global $post; // Setup global post. $post = $our_post_object; setup_postdata( $post ); // Override title if checkbox is selected. if ( true === $params['use_page_title'] ) { $params['title'] = get_the_title( $post ); } ?>
'align' . esc_attr( $params['featured_image_alignment'] ) ) ); ?>
'university_hub_widget_recent_posts', 'description' => __( 'Displays recent posts.', 'university-hub' ), 'customize_selective_refresh' => true, ); $fields = array( 'title' => array( 'label' => __( 'Title:', 'university-hub' ), 'type' => 'text', 'class' => 'widefat', ), 'post_category' => array( 'label' => __( 'Select Category:', 'university-hub' ), 'type' => 'dropdown-taxonomies', 'show_option_all' => __( 'All Categories', 'university-hub' ), ), 'post_number' => array( 'label' => __( 'Number of Posts:', 'university-hub' ), 'type' => 'number', 'default' => 4, 'css' => 'max-width:60px;', 'min' => 1, 'max' => 100, ), 'featured_image' => array( 'label' => __( 'Featured Image:', 'university-hub' ), 'type' => 'select', 'default' => 'thumbnail', 'options' => university_hub_get_image_sizes_options( true, array( 'disable', 'thumbnail' ), false ), ), 'image_width' => array( 'label' => __( 'Image Width:', 'university-hub' ), 'type' => 'number', 'description' => __( 'px', 'university-hub' ), 'css' => 'max-width:60px;', 'adjacent' => true, 'default' => 60, 'min' => 1, 'max' => 150, ), 'disable_date' => array( 'label' => __( 'Disable Date', 'university-hub' ), 'type' => 'checkbox', 'default' => false, ), ); parent::__construct( 'university-hub-recent-posts', __( 'UH: Recent Posts', 'university-hub' ), $opts, array(), $fields ); } /** * Outputs the content for the current widget instance. * * @since 1.0.0 * * @param array $args Display arguments. * @param array $instance Settings for the current widget instance. */ function widget( $args, $instance ) { $params = $this->get_params( $instance ); echo $args['before_widget']; if ( ! empty( $params['title'] ) ) { echo $args['before_title'] . $params['title'] . $args['after_title']; } $qargs = array( 'posts_per_page' => esc_attr( $params['post_number'] ), 'no_found_rows' => true, ); if ( absint( $params['post_category'] ) > 0 ) { $qargs['cat'] = $params['post_category']; } $all_posts = get_posts( $qargs ); ?>
$post ) : ?>