예제 #1
0
 /**
  * Display widget content.
  *
  * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
  * @param array $instance The settings for the particular instance of the widget
  */
 function widget($args, $instance)
 {
     extract($args);
     $instance = wp_parse_args((array) $instance, $this->defaults);
     $featured_page = new WP_Query(array('page_id' => $instance['page_id']));
     echo $before_widget . '<div class="feature-page">';
     if (!empty($instance['title'])) {
         echo $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title;
     }
     if ($featured_page->have_posts()) {
         while ($featured_page->have_posts()) {
             $featured_page->the_post();
             echo '<div class="' . implode(' ', get_post_class()) . '">';
             if (!empty($instance['show_title'])) {
                 printf('<h4 class="entry-title"><a href="%s" title="%s">%s</a></h4>', get_permalink(), the_title_attribute('echo=0'), get_the_title());
             }
             //Show image
             if (!empty($instance['show_image'])) {
                 printf('<a href="%s" title="%s" class="%s">%s</a>', get_permalink(), the_title_attribute('echo=0'), esc_attr($instance['image_alignment']), calibrefx_get_image(array('format' => 'html', 'size' => $instance['image_size'])));
             }
             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 '</div><!--end post_class()-->' . "\n\n";
         }
     }
     echo '</div>' . $after_widget;
     wp_reset_query();
 }
예제 #2
0
    /**
     * Display widget content.
     *
     * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
     * @param array $instance The settings for the particular instance of the widget
     */
    function widget($args, $instance)
    {
        global $wp_query, $calibrefx;
        extract($args);
        $instance = wp_parse_args((array) $instance, $this->defaults);
        echo $before_widget;
        if (!empty($instance['title'])) {
            echo $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title;
        }
        $query = new WP_Query(array('posts_per_page' => $instance['num_posts'], 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true));
        $no_post_thumbnail = apply_filters('no_thumbnail_image_url', CALIBREFX_IMAGES_URL . '/no-image.jpg');
        echo '<ul class="list-latest-posts">';
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
                $img = calibrefx_get_image(array('format' => 'html', 'size' => $instance['image_size']));
                $img = !empty($img) ? $img : '<img src="' . $no_post_thumbnail . '" />';
                $date_format = get_option('date_format');
                $item_class = apply_filters('calibrefx_latest_posts_item_class', calibrefx_row_class());
                $image_class = apply_filters('calibrefx_latest_posts_image_class', col_class(12, 4, 4));
                $content_class = apply_filters('calibrefx_latest_posts_content_class', col_class(12, 8, 8));
                if ($instance['show_thumbnail']) {
                    echo '
						<li>
							<div class="' . $item_class . ' latest-post-item">
								<div class="latest-post-thumb ' . $image_class . '">
									<a href="' . get_permalink() . '" class="thumbnail">' . $img . '</a>
								</div>
								<div class="latest-post-detail ' . $content_class . '">
									<h5 class="latest-post-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h5>
									<p class="latest-post-info">' . do_shortcode('[post_date]') . '</p>
									' . ($instance['show_detail'] ? get_the_content_limit($instance['detail_length']) : '') . '
								</div>
							</div>
						</li>
					';
                } else {
                    echo '
						<li>
							<div class="' . calibrefx_row_class() . ' latest-post-item">
								<div class="latest-post-detail col-lg-12 col-md-12 col-sm-12 col-xs-12">
									<h5 class="latest-post-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h5>
									<p class="latest-post-date">' . date($date_format, get_the_time('U')) . '</p>
									' . ($instance['show_detail'] ? get_the_content_limit($instance['detail_length']) : '') . '
								</div>
							</div>
						</li>
					';
                }
            }
        } else {
            echo '<li>' . __('There is no post available yet', 'calibrefx') . '</li>';
        }
        echo '</ul>';
        echo $after_widget;
        wp_reset_query();
        wp_reset_postdata();
    }
예제 #3
0
/**
 * Get an image from media gallery
 * an helper function to shorten calibrefx_get_image
 */
function calibrefx_image($args = array())
{
    $image = calibrefx_get_image($args);
    if ($image) {
        echo $image;
    } else {
        return false;
    }
}
예제 #4
0
/**
 * ==============================================================
 * Post
 * ==============================================================
 */
function calibrefx_post_item($atts, $content = null)
{
    extract(shortcode_atts(array('post_type' => 'post', 'post_id' => '', 'limit' => 0, 'limit_text' => 'Read More', 'show_title' => 1, 'is_title_link' => 0, 'show_featured_image' => 0, 'before' => '', 'after' => '', 'class' => '', 'id' => '', 'style' => ''), $atts));
    if (empty($post_id)) {
        return;
    }
    $args = array();
    if ($post_type != 'post') {
        $args['post_type'] = $post_type;
        if (!empty($post_id)) {
            $args['page_id'] = $post_id;
        }
    } else {
        if (!empty($post_id)) {
            $args['p'] = $post_id;
        }
    }
    $args['posts_per_page'] = 1;
    $query = new WP_Query($args);
    $html = '';
    if ($query->have_posts()) {
        $post_class = '';
        foreach (get_post_class() as $class_item => $val) {
            $post_class .= ' ' . $val;
        }
        $html .= '<div class="post-item' . $post_class . ' ' . $class . '">';
        while ($query->have_posts()) {
            $query->the_post();
            if ($show_title) {
                if ($is_title_link) {
                    $html .= '<h2 class="post-item-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
                } else {
                    $html .= '<h2 class="post-item-title">' . get_the_title() . '</h2>';
                }
            }
            if ($show_featured_image) {
                $post_img = calibrefx_get_image(array('format' => 'html', 'size' => ''));
                $html .= $post_img;
            }
            if ($limit) {
                $html .= get_the_content_limit($limit, $limit_text);
            } else {
                $html .= wpautop(get_the_content(), true);
            }
        }
        $html .= '</div><!-- end .post-item -->';
    }
    wp_reset_query();
    wp_reset_postdata();
    return do_shortcode($html);
}
예제 #5
0
/**
 * Get feature image to show on meta tag
 *
 * @return string image url
 */
function calibrefx_meta_image()
{
    $image = calibrefx_get_image(array('format' => 'url'));
    return apply_filters('calibrefx_meta_image', $image);
}
예제 #6
0
/**
 * Post Image
 */
function calibrefx_do_post_image()
{
    $feature_image_layout = calibrefx_get_option('feature_image_layout');
    switch ($feature_image_layout) {
        case 'none':
            return;
        case 'thumbnail':
            $img = calibrefx_get_image(array('format' => 'html', 'size' => 'thumbnail', 'attr' => array('class' => 'alignleft post-image')));
            break;
        case 'full':
        default:
            $img = calibrefx_get_image(array('format' => 'html', 'size' => 'full', 'attr' => array('class' => 'alignnone post-image img-responsive')));
            break;
    }
    $img = apply_filters('post_feature_image', $img);
    if (!$img) {
        return;
    }
    if (!is_singular()) {
        // This is an archive page
        printf('<a href="%s" title="%s" class="post-image-link">%s</a>', get_permalink(), the_title_attribute('echo=0'), $img);
    } else {
        printf('<p class="post-featured-image">%s</p>', $img);
    }
}