예제 #1
0
    public function widget($args, $instance)
    {
        global $wpdb;
        extract($args);
        $number_posts = absint($instance['number_posts']);
        /* @since 09/26/2013 */
        $post_type = isset($instance['post_type']) ? esc_attr($instance['post_type']) : 'post';
        $columns = absint($instance['columns']);
        $thumbnail_size = esc_attr($instance['thumbnail_size']);
        /* since 1.01 */
        $contentorder = array('content' => isset($instance['content_pos']) ? (int) $instance['content_pos'] : 4, 'byline' => isset($instance['byline_pos']) ? (int) $instance['byline_pos'] : 3, 'subtitle' => isset($instance['subtitle_pos']) ? (int) $instance['subtitle_pos'] : 3, 'posttitle' => isset($instance['posttitle_pos']) ? (int) $instance['posttitle_pos'] : 2, 'thumbnail' => isset($instance['image_pos']) ? (int) $instance['image_pos'] : 1);
        /* since 1.1 */
        $title_tag = isset($instance['title_tag']) ? esc_attr($instance['title_tag']) : 'h3';
        $tag = isset($instance['posttitle_tag']) ? esc_attr($instance['posttitle_tag']) : 'h2';
        $subtag = isset($instance['subtitle_tag']) ? esc_attr($instance['subtitle_tag']) : 'h3';
        if (!isset($instance['content_pos'])) {
            $instance['show_posttitle'] = 1;
            $instance['show_content'] = 1;
            $instance['sticky'] = 0;
        }
        $suppress_posttitle_link = isset($instance['suppress_posttitle_link']) ? (bool) ($instance['suppress_posttitle_link'] == 1) : false;
        $suppress_postthumbnail_link = isset($instance['suppress_postthumbnail_link']) ? (bool) ($instance['suppress_postthumbnail_link'] == 1) : false;
        $suppress_category_link = isset($instance['suppress_category_link']) ? (bool) ($instance['suppress_category_link'] == 1) : false;
        if (!isset($instance['show_subtitle'])) {
            $instance['show_subtitle'] = 0;
        }
        asort($contentorder, SORT_NUMERIC);
        foreach ($contentorder as $key => $value) {
            if ($instance['show_' . $key]) {
                $new_sort[] = $key;
            }
        }
        $el = 'div';
        $html5 = xtreme_is_html5();
        if ($html5) {
            $el = 'article';
        }
        echo $before_widget;
        if ($columns !== 1) {
            echo '<div class="ym-grid linearize-level-1">';
        }
        for ($i = 0; $i < $columns; $i++) {
            if ($columns !== 1) {
                echo "<div class='" . $this->classes[$columns][$i]['outer'] . "'>\n";
                echo "<div class='" . $this->classes[$columns][$i]['inner'] . "'>\n";
            }
            /* @since 09/26/2013 */
            $tax_names = get_object_taxonomies($post_type);
            if (!empty($tax_names) && in_array('category', $tax_names)) {
                $category = $instance['category-' . $i];
            } else {
                $category = '';
            }
            $r = new WP_Query(array('cat' => $category, 'showposts' => $number_posts, 'offset' => (int) $instance['offset'], 'nopaging' => 0, 'post_type' => $post_type, 'post_status' => 'publish', XF_STICKY_HANDLING => 1, 'orderby' => esc_attr($instance['orderby']), 'order' => esc_attr(strtoupper($instance['sort']))));
            if ($r->have_posts()) {
                $x = 0;
                while ($r->have_posts()) {
                    $r->the_post();
                    $x++;
                    if ($x === 1 && '' !== $category && $instance['title']) {
                        if ((int) $instance['category-' . $i] === 0) {
                            $title = __('All Categories', XF_TEXTDOMAIN);
                            $cls = 'category-all';
                        } else {
                            $cat = get_category($instance['category-' . $i]);
                            $cls = 'category-' . $cat->slug;
                            if (!$suppress_category_link) {
                                $title = '<a href="' . esc_attr(get_category_link($instance['category-' . $i])) . '">' . esc_attr($cat->name) . '</a>';
                            } else {
                                $title = esc_attr($cat->name);
                            }
                        }
                        echo '<' . $title_tag . ' class="widget-title ' . $cls . '">' . $title . '</' . $title_tag . '>';
                    }
                    ?>
					<<?php 
                    echo $el;
                    ?>
 <?php 
                    post_class();
                    ?>
>
					<?php 
                    if (isset($new_sort)) {
                        $c = count($new_sort);
                        for ($y = 0; $y < $c; $y++) {
                            switch ($new_sort[$y]) {
                                case 'thumbnail':
                                    if (!$suppress_postthumbnail_link) {
                                        xtreme_post_thumbnail($thumbnail_size, esc_attr($instance['image_alignment']));
                                    } else {
                                        xtreme_widget_post_thumbnail($thumbnail_size, esc_attr($instance['image_alignment']));
                                    }
                                    break;
                                case 'subtitle':
                                    xtreme_widget_post_subtitle($subtag);
                                    break;
                                case 'posttitle':
                                    if ($html5) {
                                        echo '<header>';
                                    }
                                    xtreme_widget_post_headline($tag, !$suppress_posttitle_link);
                                    if ($html5 && $new_sort[$y + 1] !== 'byline') {
                                        echo '</header>';
                                    }
                                    break;
                                case 'byline':
                                    if (!$html5) {
                                        xtreme_byline();
                                    } else {
                                        xtreme_html5_byline();
                                        if ($new_sort[$y - 1] == 'posttitle') {
                                            echo '</header>';
                                        }
                                    }
                                    break;
                                case 'content':
                                    echo '<div class="entry-content">';
                                    switch ($instance['content_type']) {
                                        case 'xtreme_excerpt':
                                            xtreme_excerpt($instance['excerpt_length'], esc_html($instance['excerpt_morelink_text']), esc_html($instance['excerpt_more']));
                                            break;
                                        case 'excerpt':
                                            $new_excerpt = wptexturize(get_the_excerpt());
                                            echo "<p>{$new_excerpt} <span class='read-more'><a href='" . get_permalink() . "' title='" . __('Read more about', XF_TEXTDOMAIN) . ' ' . esc_attr(get_the_title()) . "'>" . esc_html($instance['excerpt_morelink_text']) . "</a></span></p>";
                                            break;
                                        case 'content':
                                            the_content();
                                            break;
                                    }
                                    echo '</div>';
                                    break;
                            }
                        }
                        echo '</' . $el . '>';
                    }
                }
                if ($columns !== 1) {
                    echo "</div></div>";
                }
                wp_reset_query();
            } else {
                echo __('No Posts so far.', XF_TEXTDOMAIN) . '</div></div>';
            }
        }
        if ($columns !== 1) {
            echo '</div>';
        }
        echo $after_widget;
    }
    function widget($args, $instance)
    {
        global $wpdb;
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
        $columns = absint($instance['columns']);
        $thumbnail_size = esc_attr($instance['thumbnail_size']);
        if (!isset($instance['as_backgroundimage'])) {
            $instance['as_backgroundimage'] = 0;
        }
        if (!isset($instance['wrap_content'])) {
            $instance['wrap_content'] = 1;
        }
        $el = 'div';
        $html5 = xtreme_is_html5();
        if ($html5) {
            $el = 'article';
        }
        $contentorder = array('content' => isset($instance['content_pos']) ? (int) $instance['content_pos'] : 4, 'subtitle' => isset($instance['subtitle_pos']) ? (int) $instance['subtitle_pos'] : 3, 'posttitle' => isset($instance['posttitle_pos']) ? (int) $instance['posttitle_pos'] : 2, 'thumbnail' => isset($instance['image_pos']) ? (int) $instance['image_pos'] : 1);
        $suppress_posttitle_link = isset($instance['suppress_posttitle_link']) ? (bool) ($instance['suppress_posttitle_link'] == 1) : false;
        $suppress_subtitle_link = isset($instance['suppress_subtitle_link']) ? (bool) ($instance['suppress_subtitle_link'] == 1) : false;
        $tag = isset($instance['posttitle_tag']) ? esc_attr($instance['posttitle_tag']) : 'h2';
        $subtag = isset($instance['subtitle_tag']) ? esc_attr($instance['subtitle_tag']) : 'h3';
        $instance['show_content'] = 1;
        if (!isset($instance['show_headline'])) {
            $instance['show_posttitle'] = 1;
        }
        if (!isset($instance['show_subtitle'])) {
            $instance['show_subtitle'] = 0;
        }
        asort($contentorder, SORT_NUMERIC);
        foreach ($contentorder as $key => $value) {
            if ($instance['show_' . $key]) {
                $new_sort[] = $key;
            }
        }
        echo $before_widget;
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        for ($i = 0; $i < $columns; $i++) {
            $r = new WP_Query(array('page_id' => $instance['page_id-' . $i]));
            if ($r->have_posts()) {
                while ($r->have_posts()) {
                    $r->the_post();
                    echo $this->html_before($columns, $i + 1, $instance['use_box_bottom']);
                    ?>
					<<?php 
                    echo $el;
                    ?>
 <?php 
                    post_class();
                    ?>
>
					<?php 
                    if (isset($new_sort)) {
                        $c = count($new_sort);
                        for ($y = 0; $y < $c; $y++) {
                            switch ($new_sort[$y]) {
                                case 'thumbnail':
                                    if ($instance['as_backgroundimage'] == 0) {
                                        xtreme_post_thumbnail($thumbnail_size, esc_attr($instance['image_alignment']));
                                    } else {
                                        xtreme_background_post_thumbnail($thumbnail_size, esc_attr($instance['image_alignment']), esc_html($instance['excerpt_morelink_text']));
                                    }
                                    break;
                                case 'subtitle':
                                    xtreme_widget_post_subtitle($subtag, !$suppress_subtitle_link, true);
                                    break;
                                case 'posttitle':
                                    if ($html5) {
                                        echo '<header>';
                                    }
                                    $custom_posttitle = esc_html($instance['custom_posttitle-' . $i]);
                                    xtreme_widget_post_headline($tag, !$suppress_posttitle_link, true, $custom_posttitle);
                                    if ($html5) {
                                        echo '</header>';
                                    }
                                    break;
                                case 'content':
                                    if ($instance['wrap_content'] == 1) {
                                        echo '<div class="entry-content">';
                                    }
                                    switch ($instance['content_type-' . $i]) {
                                        case 'xtreme_excerpt':
                                            if (!$instance['use_box_bottom']) {
                                                xtreme_excerpt($instance['excerpt_length-' . $i], esc_html($instance['excerpt_morelink_text-' . $i]), esc_html($instance['excerpt_more-' . $i]));
                                            } else {
                                                xtreme_excerpt($instance['excerpt_length-' . $i], '', esc_html($instance['excerpt_more-' . $i]));
                                            }
                                            break;
                                        case 'content':
                                            the_content();
                                            break;
                                        case 'excerpt':
                                            if (!$instance['use_box_bottom']) {
                                                $new_excerpt = wptexturize(get_the_excerpt());
                                                echo "<p>{$new_excerpt} <span class='read-more'><a href='" . get_permalink() . "' title='" . __('Read more about', XF_TEXTDOMAIN) . ' ' . esc_attr(get_the_title()) . "'>" . esc_html($instance['excerpt_morelink_text-' . $i]) . "</a></span></p>";
                                            } else {
                                                the_excerpt();
                                            }
                                            break;
                                    }
                                    if ($instance['wrap_content'] == 1) {
                                        echo '</div>';
                                    }
                                    break;
                            }
                        }
                        echo '</' . $el . '>';
                        $link[] = array('url' => get_permalink(), 'title' => get_the_title(), 'read_more' => esc_html($instance['excerpt_morelink_text-' . $i]));
                    }
                }
                wp_reset_query();
                echo $this->html_after($columns, $i + 1, $instance['use_box_bottom'], $link);
            }
        }
        unset($link);
        echo $after_widget;
    }
    function widget($args, $instance)
    {
        global $wpdb;
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
        if ($instance['number_posts'] < 1) {
            $instance['number_posts'] = 1;
        }
        $columns = absint($instance['columns']);
        $rows = absint($instance['rows']);
        $thumbnail_size = esc_attr($instance['thumbnail_size']);
        if (!isset($instance['as_backgroundimage'])) {
            $instance['as_backgroundimage'] = 0;
        }
        if (!isset($instance['wrap_content'])) {
            $instance['wrap_content'] = 1;
        }
        $el = 'div';
        $html5 = xtreme_is_html5();
        if ($html5) {
            $el = 'article';
        }
        $contentorder = array('content' => isset($instance['content_pos']) ? (int) $instance['content_pos'] : 4, 'byline' => isset($instance['byline_pos']) ? (int) $instance['byline_pos'] : 3, 'subtitle' => isset($instance['subtitle_pos']) ? (int) $instance['subtitle_pos'] : 3, 'posttitle' => isset($instance['posttitle_pos']) ? (int) $instance['posttitle_pos'] : 2, 'thumbnail' => isset($instance['image_pos']) ? (int) $instance['image_pos'] : 1);
        $suppress_posttitle_link = isset($instance['suppress_posttitle_link']) ? (bool) ($instance['suppress_posttitle_link'] == 1) : false;
        $tag = isset($instance['posttitle_tag']) ? esc_attr($instance['posttitle_tag']) : 'h2';
        $subtag = isset($instance['subtitle_tag']) ? esc_attr($instance['subtitle_tag']) : 'h3';
        if (!isset($instance['content_pos'])) {
            $instance['show_posttitle'] = 1;
            $instance['show_content'] = 1;
            $instance['sticky'] = 0;
        }
        if (!isset($instance['show_subtitle'])) {
            $instance['show_subtitle'] = 0;
        }
        asort($contentorder, SORT_NUMERIC);
        foreach ($contentorder as $key => $value) {
            if ($instance['show_' . $key]) {
                $new_sort[] = $key;
            }
        }
        $query_args = array('showposts' => (int) $instance['number_posts'], 'offset' => (int) $instance['offset'], 'nopaging' => 0, 'post_type' => 'post', 'post_status' => 'publish', XF_STICKY_HANDLING => (bool) $instance['sticky'], 'orderby' => esc_attr($instance['orderby']));
        if ($query_args[XF_STICKY_HANDLING] === true) {
            $query_args['post__not_in'] = get_option('sticky_posts');
        }
        if (array_key_exists('hide_child_cat', $instance) && (bool) $instance['hide_child_cat']) {
            $query_args['category__in'] = $instance['category'];
        } else {
            $query_args['cat'] = $instance['category'];
        }
        $r = new WP_Query($query_args);
        if ($r->have_posts()) {
            $i = 0;
            $count = $r->post_count;
            echo $before_widget;
            if ($title) {
                echo $before_title . $title . $after_title;
            }
            while ($r->have_posts()) {
                $r->the_post();
                $i++;
                echo $this->html_before($columns, $i, $instance['use_box_bottom']);
                ?>
				<<?php 
                echo $el;
                ?>
 <?php 
                post_class();
                ?>
>
				<?php 
                if (isset($new_sort)) {
                    $c = count($new_sort);
                    for ($y = 0; $y < $c; $y++) {
                        switch ($new_sort[$y]) {
                            case 'thumbnail':
                                if ($instance['as_backgroundimage'] == 0) {
                                    xtreme_post_thumbnail($thumbnail_size, esc_attr($instance['image_alignment']));
                                } else {
                                    xtreme_background_post_thumbnail($thumbnail_size, esc_attr($instance['image_alignment']), esc_html($instance['excerpt_morelink_text']));
                                }
                                break;
                            case 'subtitle':
                                xtreme_widget_post_subtitle($subtag);
                                break;
                            case 'posttitle':
                                if ($html5) {
                                    echo '<header>';
                                }
                                xtreme_widget_post_headline($tag, !$suppress_posttitle_link);
                                if ($html5 && $new_sort[$y + 1] !== 'byline') {
                                    echo '</header>';
                                }
                                break;
                            case 'byline':
                                if (!$html5) {
                                    xtreme_byline();
                                } else {
                                    xtreme_html5_byline();
                                    if ($new_sort[$y - 1] == 'posttitle') {
                                        echo '</header>';
                                    }
                                }
                                break;
                            case 'content':
                                if ($instance['wrap_content'] == 1) {
                                    echo '<div class="entry-content">';
                                }
                                switch ($instance['content_type']) {
                                    case 'xtreme_excerpt':
                                        if (!$instance['use_box_bottom']) {
                                            xtreme_excerpt($instance['excerpt_length'], esc_html($instance['excerpt_morelink_text']), esc_html($instance['excerpt_more']));
                                        } else {
                                            xtreme_excerpt($instance['excerpt_length'], '', esc_html($instance['excerpt_more']));
                                        }
                                        break;
                                    case 'excerpt':
                                        the_excerpt();
                                        if (!$instance['use_box_bottom']) {
                                            echo " <p><span class='read-more'><a href='" . get_permalink() . "' title='" . __('Read more about', XF_TEXTDOMAIN) . ' ' . esc_attr(get_the_title()) . "'>" . esc_html($instance['excerpt_morelink_text']) . "</a></span></p>";
                                        }
                                        break;
                                }
                                if ($instance['wrap_content'] == 1) {
                                    echo '</div>';
                                }
                                break;
                        }
                    }
                    echo '</' . $el . '>';
                    $link[] = array('url' => get_permalink(), 'title' => get_the_title());
                    echo $this->html_after($columns, $i, $instance['use_box_bottom'], $link, esc_html($instance['excerpt_morelink_text']));
                }
            }
            wp_reset_query();
            $rest = $i % $columns;
            if ($rest !== 0) {
                while ($rest < $columns) {
                    $rest++;
                    $i++;
                    $link[] = array('url' => '#blank', 'title' => '');
                    echo $this->html_before($columns, $rest, $instance['use_box_bottom']);
                    echo "&nbsp;";
                    echo $this->html_after($columns, $i, $instance['use_box_bottom'], $link, esc_html($instance['excerpt_morelink_text']));
                }
            }
            echo $after_widget;
        }
        unset($link);
    }
예제 #4
0
    public function widget($args, $instance)
    {
        global $wpdb;
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
        if ($instance['number_posts'] < 1) {
            $instance['number_posts'] = 1;
        }
        /* @since 09/26/2013 */
        $post_type = isset($instance['post_type']) ? esc_attr($instance['post_type']) : 'post';
        $columns = absint($instance['columns']);
        $rows = absint($instance['rows']);
        $thumbnail_size = esc_attr($instance['thumbnail_size']);
        if (!isset($instance['as_backgroundimage'])) {
            $instance['as_backgroundimage'] = 0;
        }
        if (!isset($instance['wrap_content'])) {
            $instance['wrap_content'] = 1;
        }
        $el = 'div';
        $html5 = xtreme_is_html5();
        if ($html5) {
            $el = 'article';
        }
        /* since 1.01 */
        $contentorder = array('content' => isset($instance['content_pos']) ? (int) $instance['content_pos'] : 4, 'byline' => isset($instance['byline_pos']) ? (int) $instance['byline_pos'] : 3, 'subtitle' => isset($instance['subtitle_pos']) ? (int) $instance['subtitle_pos'] : 3, 'posttitle' => isset($instance['posttitle_pos']) ? (int) $instance['posttitle_pos'] : 2, 'thumbnail' => isset($instance['image_pos']) ? (int) $instance['image_pos'] : 1);
        $suppress_posttitle_link = isset($instance['suppress_posttitle_link']) ? (bool) ($instance['suppress_posttitle_link'] == 1) : false;
        $tag = isset($instance['posttitle_tag']) ? esc_attr($instance['posttitle_tag']) : 'h2';
        $subtag = isset($instance['subtitle_tag']) ? esc_attr($instance['subtitle_tag']) : 'h3';
        if (!isset($instance['content_pos'])) {
            $instance['show_posttitle'] = 1;
            $instance['show_content'] = 1;
            $instance['sticky'] = 0;
        }
        if (!isset($instance['show_subtitle'])) {
            $instance['show_subtitle'] = 0;
        }
        asort($contentorder, SORT_NUMERIC);
        foreach ($contentorder as $key => $value) {
            if ($instance['show_' . $key]) {
                $new_sort[] = $key;
            }
        }
        /* @since 09/26/2013 */
        $tax_names = get_object_taxonomies($post_type);
        if (!empty($tax_names) && in_array('category', $tax_names)) {
            $category = $instance['category'];
        } else {
            $category = '';
        }
        $query_args = array('cat' => $instance['category'], 'showposts' => (int) $instance['number_posts'], 'offset' => (int) $instance['offset'], 'nopaging' => 0, 'post_type' => $post_type, 'post_status' => 'publish', XF_STICKY_HANDLING => (bool) $instance['sticky'], 'orderby' => esc_attr($instance['orderby']), 'order' => esc_attr($instance['order']));
        /**
         * exclude the current post_id on is_singular()
         * @since 1.6.3
         * @link https://github.com/inpsyde/xtreme-one/issues/184
         */
        if (is_singular()) {
            $id = get_the_ID();
            if (!!$id) {
                $query_args['post__not_in'] = array($id);
            }
        }
        $r = new WP_Query($query_args);
        if ($r->have_posts()) {
            $i = 0;
            $count = $r->post_count;
            echo $before_widget;
            if ($title) {
                echo $before_title . $title . $after_title;
            }
            while ($r->have_posts()) {
                $r->the_post();
                echo $this->html_before($columns, $i);
                $i++;
                ?>
				<<?php 
                echo $el;
                ?>
 <?php 
                post_class();
                ?>
>
				<?php 
                if (isset($new_sort)) {
                    $c = count($new_sort);
                    for ($y = 0; $y < $c; $y++) {
                        switch ($new_sort[$y]) {
                            case 'thumbnail':
                                if ($instance['as_backgroundimage'] == 0) {
                                    xtreme_post_thumbnail($thumbnail_size, esc_attr($instance['image_alignment']));
                                } else {
                                    xtreme_background_post_thumbnail($thumbnail_size, esc_attr($instance['image_alignment']), esc_html($instance['excerpt_morelink_text']));
                                }
                                break;
                            case 'subtitle':
                                xtreme_widget_post_subtitle($subtag);
                                break;
                            case 'posttitle':
                                if ($html5) {
                                    echo '<header>';
                                }
                                xtreme_widget_post_headline($tag, !$suppress_posttitle_link);
                                if ($html5 && $new_sort[$y + 1] !== 'byline') {
                                    echo '</header>';
                                }
                                break;
                            case 'byline':
                                if (!$html5) {
                                    xtreme_byline();
                                } else {
                                    xtreme_html5_byline();
                                    if ($y !== 0) {
                                        if ($new_sort[$y - 1] == 'posttitle') {
                                            echo '</header>';
                                        }
                                    }
                                }
                                break;
                            case 'content':
                                if ($instance['wrap_content'] == 1) {
                                    echo '<div class="entry-content">';
                                }
                                switch ($instance['content_type']) {
                                    case 'xtreme_excerpt':
                                        $excerpt_length = esc_attr($instance['excerpt_length']);
                                        $excerpt_more_text = esc_html($instance['excerpt_morelink_text']);
                                        $excerpt_more = esc_html($instance['excerpt_more']);
                                        $excerpt_show_tags = isset($instance['excerpt_show_tags']);
                                        xtreme_excerpt($excerpt_length, $excerpt_more_text, $excerpt_more, true, $excerpt_show_tags);
                                        break;
                                    case 'excerpt':
                                        the_excerpt();
                                        echo " <p><span class='read-more'><a href='" . get_permalink() . "' title='" . __('Read more about', XF_TEXTDOMAIN) . ' ' . esc_attr(get_the_title()) . "'>" . esc_html($instance['excerpt_morelink_text']) . "</a></span></p>";
                                        break;
                                    case 'content':
                                        the_content();
                                        break;
                                }
                                if ($instance['wrap_content'] == 1) {
                                    echo '</div>';
                                }
                                break;
                        }
                    }
                    echo '</' . $el . '>';
                    echo $this->html_after($columns, $i);
                }
            }
            wp_reset_query();
            if ($count < (int) $instance['number_posts']) {
                while ($count < (int) $instance['number_posts']) {
                    $count++;
                    echo $this->html_before($columns, $count);
                    echo "&nbsp;";
                    echo $this->html_after($columns, $count);
                }
            }
            echo $after_widget;
        }
    }