Пример #1
0
    function kopa_load_timeline_posts_fn($month, $year, $paged)
    {
        $args = array('date_query' => array('post_type' => array('post'), 'post_status' => array('publish'), 'ignore_sticky_posts' => true, array('year' => $year, 'month' => $month)));
        if ($paged) {
            $args['paged'] = $paged;
        }
        $posts = new WP_Query($args);
        $exceprt_type = KopaOptions::get_option('exceprt_type', 'limit');
        $excerpt_limit = KopaOptions::get_option('excerpt_limit', 200, 'Int');
        $metadata = array();
        $metadata['date'] = false;
        $metadata['comments'] = KopaOptions::get_option('is_display_comments', true, 'Boolean');
        $metadata['views'] = KopaOptions::get_option('is_display_views', true, 'Boolean');
        $metadata['likes'] = KopaOptions::get_option('is_display_likes', true, 'Boolean');
        $metadata['readmore'] = KopaOptions::get_option('is_display_readmore', true, 'Boolean');
        global $post;
        while ($posts->have_posts()) {
            $posts->the_post();
            $post_id = get_the_ID();
            $post_title = get_the_title();
            $post_url = get_permalink();
            $post_format = get_post_format();
            if (!is_sticky()) {
                ?>
                <div class="item clearfix">
                    <p class="kopa-timeline-date-small"><?php 
                echo get_the_date();
                ?>
</p>
                    <?php 
                if (has_post_thumbnail()) {
                    $image_full = KopaImage::get_post_image_src($post_id, 'full');
                    $image_croped = KopaImage::get_post_image_src($post_id, 'size_09');
                    ?>
                        <div class="kopa-thumb">
                            <img src="<?php 
                    echo $image_croped;
                    ?>
" alt="<?php 
                    echo $post_title;
                    ?>
"/>
                            <div class="mask"></div>
                            <a href="<?php 
                    echo $post_url;
                    ?>
" class="icon-link fa fa-link fa-flip-horizontal"></a>
                            <span class="icon-zoom-in fa fa-search-plus" onclick="KopaLightbox.open_image('<?php 
                    echo $image_full;
                    ?>
');"></span>
                        </div>
                        <?php 
                }
                ?>

                    <div class="kp-caption">
                        <h4 class="post-title"><a href="<?php 
                echo $post_url;
                ?>
" title="<?php 
                echo $post_title;
                ?>
"><?php 
                echo $post_title;
                ?>
</a></h4>

                        <ul class="kp-meta-post list-inline">       
                            <?php 
                $is_first = true;
                foreach ($metadata as $key => $val) {
                    if ($val) {
                        $class = $is_first ? 'metadata-first' : '';
                        $is_first = false;
                        switch ($key) {
                            case 'date':
                                printf('<li class="%s">%s<span>%s</span></li>', $class, KopaIcon::getIconDatetime(), get_the_date());
                                break;
                            case 'comments':
                                ?>
                                            <li class="<?php 
                                echo $class;
                                ?>
"><?php 
                                echo KopaIcon::getIconComment();
                                ?>
<span><?php 
                                comments_popup_link(__('No Comment', kopa_get_domain()), __('1 Comment', kopa_get_domain()), __('% Comments', kopa_get_domain()), '', __('0 Comment', kopa_get_domain()));
                                ?>
</span></li>                                            
                                            <?php 
                                break;
                            case 'views':
                                printf('<li class="%s">%s<span>%s</span></li>', $class, KopaIcon::getIconView(), KopaUtil::get_views($post_id, true));
                                break;
                            case 'likes':
                                printf('<li class="%s">%s</li>', $class, KopaUtil::kopa_get_like_button($post_id, true));
                                break;
                        }
                    }
                }
                ?>
                        </ul>

                        <?php 
                if ('excerpt' == $exceprt_type) {
                    if (has_excerpt()) {
                        printf('<p>%s</p>', get_the_excerpt());
                    } else {
                        global $post;
                        if (strpos($post->post_content, '<!--more-->')) {
                            the_content(' ');
                        } else {
                            printf('<p>%s</p>', get_the_excerpt());
                        }
                    }
                } elseif ('full' == $exceprt_type) {
                    global $more;
                    $more = true;
                    the_content();
                } else {
                    if ($excerpt_limit) {
                        $excerpt = KopaUtil::substr($post->post_content, $excerpt_limit);
                        echo $excerpt ? sprintf('<p>%s</p>', $excerpt) : '';
                    }
                }
                ?>

                        <?php 
                if ($metadata['readmore'] && 'full' != $exceprt_type) {
                    ?>
                            <a href="<?php 
                    echo $post_url;
                    ?>
" class="read-more"><?php 
                    _e('Read more', kopa_get_domain());
                    ?>
</a>
                        <?php 
                }
                ?>

                    </div>
                    <!-- kp-caption -->
                    <div class="more-i">
                        <div class="more-time">
                            <span><?php 
                echo get_the_date('M d');
                ?>
</span> 
                            <i><?php 
                echo get_the_date('Y');
                ?>
</i>
                        </div>
                        <span></span>
                        <?php 
                echo KopaIcon::getIconPostFormat($post_format);
                ?>
                        
                    </div>
                    <!-- more i -->
                </div>
                <?php 
            }
        }
        wp_reset_postdata();
    }
    public function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
        echo $before_widget;
        if (!empty($title)) {
            echo $before_title . $title . $after_title;
        }
        $query = $this->build_query($instance);
        $posts = new WP_Query($query);
        if ($posts->have_posts()) {
            $metadata = array();
            $metadata['date'] = 'true' != $instance['is_hide_created_date'] ? true : false;
            $metadata['comments'] = 'true' != $instance['is_hide_comments'] ? true : false;
            global $post;
            ?>
            <div class="widget-content">
                <ul class="list-unstyled">
                    <?php 
            $is_first = true;
            while ($posts->have_posts()) {
                $posts->the_post();
                $post_id = get_the_ID();
                $post_title = get_the_title();
                $post_url = get_permalink();
                if ($is_first) {
                    $is_first = false;
                    ?>
                            <li <?php 
                    post_class('style-1');
                    ?>
>
                                <div class="item clearfix">
                                    <?php 
                    if (has_post_thumbnail()) {
                        $image_croped = KopaImage::get_post_image_src($post_id, 'size_02');
                        ?>
                                        <a href="<?php 
                        echo $post_url;
                        ?>
" class="pull-left">
                                            <img src="<?php 
                        echo $image_croped;
                        ?>
" alt="">                                            
                                        </a>               
                                        <?php 
                    }
                    ?>
                                    

                                    <div class="item-right">
                                        <?php 
                    if ('true' != $instance['is_hide_title']) {
                        ?>
                                        
                                            <h4 class="post-title"><a href="<?php 
                        echo $post_url;
                        ?>
"><?php 
                        echo $post_title;
                        ?>
</a></h4>
                                        <?php 
                    }
                    ?>

                                        <?php 
                    if ($metadata['date'] || $metadata['comments']) {
                        ?>

                                            <ul class="kp-meta-post list-inline">    
                                                <?php 
                        $is_metadata_first = true;
                        foreach ($metadata as $key => $val) {
                            if ($val) {
                                $class = $is_metadata_first ? 'metadata-first' : '';
                                $is_metadata_first = false;
                                switch ($key) {
                                    case 'date':
                                        printf('<li class="%s">%s<span>%s</span></li>', $class, KopaIcon::getIconDatetime(), get_the_date());
                                        break;
                                    case 'comments':
                                        ?>
                                                                <li class="<?php 
                                        echo $class;
                                        ?>
"><?php 
                                        echo KopaIcon::getIconComment();
                                        ?>
<span><?php 
                                        comments_popup_link(__('No Comment', kopa_get_domain()), __('1 Comment', kopa_get_domain()), __('% Comments', kopa_get_domain()), '', __('0 Comment', kopa_get_domain()));
                                        ?>
</span></li>                                            
                                                                <?php 
                                        break;
                                }
                            }
                        }
                        ?>
                                   
                                            </ul> 

                                        <?php 
                    }
                    ?>

                                        <?php 
                    if ('true' != $instance['is_hide_excerpt']) {
                        if ((int) $instance['excerpt_character_limit'] > 0) {
                            $excerpt = KopaUtil::substr($post->post_content, (int) $instance['excerpt_character_limit']);
                            echo $excerpt ? sprintf('<p>%s</p>', $excerpt) : '';
                        } else {
                            the_excerpt();
                        }
                    }
                    ?>
                                        <?php 
                    if ('true' != $instance['is_hide_readmore']) {
                        ?>
                                            
                                            <a class="read-more" href="<?php 
                        echo $post_url;
                        ?>
"><?php 
                        _e('Read more', kopa_get_domain());
                        ?>
</a>
                                        <?php 
                    }
                    ?>

                                    </div>

                                </div>
                            </li>
                            <?php 
                } else {
                    ?>
                            <li>
                                <div class="item clearfix">
                                    <?php 
                    if (has_post_thumbnail()) {
                        $image_croped = KopaImage::get_post_image_src($post_id, 'size_00');
                        ?>
                                        <a href="<?php 
                        echo $post_url;
                        ?>
" class="pull-left">
                                            <img src="<?php 
                        echo $image_croped;
                        ?>
" alt="">                                            
                                        </a>               
                                        <?php 
                    }
                    ?>

                                    <div class="item-right">
                                        <?php 
                    if ('true' != $instance['is_hide_title']) {
                        ?>
                                        
                                            <h4 class="post-title"><a href="<?php 
                        echo $post_url;
                        ?>
"><?php 
                        echo $post_title;
                        ?>
</a></h4>
                                        <?php 
                    }
                    ?>

                                        <?php 
                    if ($metadata['date'] || $metadata['comments']) {
                        ?>

                                            <ul class="kp-meta-post list-inline">    
                                                <?php 
                        $is_metadata_first = true;
                        foreach ($metadata as $key => $val) {
                            if ($val) {
                                $class = $is_metadata_first ? 'metadata-first' : '';
                                $is_metadata_first = false;
                                switch ($key) {
                                    case 'date':
                                        printf('<li class="%s">%s<span>%s</span></li>', $class, KopaIcon::getIconDatetime(), get_the_date());
                                        break;
                                        break;
                                }
                            }
                        }
                        ?>
                                   
                                            </ul> 

                                        <?php 
                    }
                    ?>

                                    </div>
                                </div>
                            </li>
                        <?php 
                }
            }
            ?>
                </ul>
            </div>
            <?php 
        } else {
            _e('Posts not found. Pleae config this widget again!', kopa_get_domain());
        }
        wp_reset_postdata();
        echo $after_widget;
    }
Пример #3
0
                            ?>
                            
                                                        </li>
                                                        <?php 
                        }
                        break;
                    case 'date':
                        printf('<li class="%s">%s<span>%s</span></li>', $class, KopaIcon::getIconDatetime(), get_the_date());
                        break;
                    case 'comments':
                        ?>
                                                    <li class="<?php 
                        echo $class;
                        ?>
"><?php 
                        echo KopaIcon::getIconComment();
                        ?>
<span><?php 
                        comments_popup_link(__('No Comment', kopa_get_domain()), __('1 Comment', kopa_get_domain()), __('% Comments', kopa_get_domain()), '', __('0 Comment', kopa_get_domain()));
                        ?>
</span></li>                                            
                                                    <?php 
                        break;
                    case 'views':
                        printf('<li class="singular-view-count %s">%s<span>%s</span></li>', $class, KopaIcon::getIconView(), KopaUtil::get_views($post_id, true));
                        break;
                    case 'likes':
                        printf('<li class="%s">%s</li>', $class, KopaUtil::kopa_get_like_button($post_id, true));
                        break;
                    case 'shares':
                        printf('<li class="singular-shares %s"><a class="addthis_button_compact" addthis:url="%s" href="#" rel="nofollow">%s&nbsp;%s</a></li>', $class, $post_url, KopaIcon::getIconShare(), __('Share', kopa_get_domain()));
    public function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
        echo $before_widget;
        if (!empty($title)) {
            echo $before_title . $title . $after_title;
        }
        $query = $this->build_query($instance);
        $posts = new WP_Query($query);
        if ($posts->have_posts()) {
            global $post;
            $metadata = array();
            $metadata['date'] = 'true' != $instance['is_hide_created_date'] ? true : false;
            $metadata['comments'] = 'true' != $instance['is_hide_comments'] ? true : false;
            $metadata['views'] = 'true' != $instance['is_hide_views'] ? true : false;
            $metadata['likes'] = 'true' != $instance['is_hide_likes'] ? true : false;
            ?>
            <div class="widget-content">
                <div class="owl-carousel">
                    <?php 
            while ($posts->have_posts()) {
                $posts->the_post();
                $post_id = get_the_ID();
                $post_title = get_the_title();
                $post_url = get_permalink();
                if (has_post_thumbnail()) {
                    $image_croped = KopaImage::get_post_image_src($post_id, 'size_05');
                    ?>
                            <div <?php 
                    post_class('item');
                    ?>
>

                                <a href="<?php 
                    echo $post_url;
                    ?>
"><img src="<?php 
                    echo $image_croped;
                    ?>
" alt="<?php 
                    echo $post_title;
                    ?>
"></a>

                                <div class="kp-caption">
                                    <?php 
                    if ('true' != $instance['is_hide_title']) {
                        ?>
                                        <h3 class="post-title"><a href="<?php 
                        echo $post_url;
                        ?>
"><?php 
                        echo $post_title;
                        ?>
</a></h3>
                                    <?php 
                    }
                    ?>
                                </div>

                                <?php 
                    if ($metadata['date'] || $metadata['comments'] || $metadata['views'] || $metadata['likes']) {
                        ?>
                                    <footer>
                                        <ul class="kp-meta-post list-inline">    
                                            <?php 
                        $is_metadata_first = true;
                        foreach ($metadata as $key => $val) {
                            if ($val) {
                                $class = $is_metadata_first ? 'metadata-first' : '';
                                $is_metadata_first = false;
                                switch ($key) {
                                    case 'date':
                                        printf('<li class="%s">%s<span>%s</span></li>', $class, KopaIcon::getIconDatetime(), get_the_date());
                                        break;
                                    case 'comments':
                                        ?>
                                                            <li class="<?php 
                                        echo $class;
                                        ?>
"><?php 
                                        echo KopaIcon::getIconComment();
                                        ?>
<span><?php 
                                        comments_popup_link(__('No Comment', kopa_get_domain()), __('1 Comment', kopa_get_domain()), __('% Comments', kopa_get_domain()), '', __('0 Comment', kopa_get_domain()));
                                        ?>
</span></li>                                            
                                                            <?php 
                                        break;
                                    case 'views':
                                        printf('<li class="%s">%s<span>%s</span></li>', $class, KopaIcon::getIconView(), KopaUtil::get_views($post_id, true));
                                        break;
                                    case 'likes':
                                        printf('<li class="%s">%s</li>', $class, KopaUtil::kopa_get_like_button($post_id, true));
                                        break;
                                }
                            }
                        }
                        ?>
                                   
                                        </ul> 
                                    </footer>
                                <?php 
                    }
                    ?>

                            </div>
                            <?php 
                }
            }
            ?>
                </div>
            </div>
            <?php 
        } else {
            _e('Posts not found. Pleae config this widget again!', kopa_get_domain());
        }
        wp_reset_postdata();
        echo $after_widget;
    }
    public function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
        echo $before_widget;
        if (!empty($title)) {
            echo $before_title . $title . $after_title;
        }
        $query = $this->build_query($instance);
        $posts = new WP_Query($query);
        if ($posts->have_posts()) {
            global $post;
            ?>
            <div class="widget-content clearfix">
                <?php 
            $metadata = array();
            $metadata['date'] = 'true' != $instance['is_hide_created_date'] ? true : false;
            $metadata['comments'] = 'true' != $instance['is_hide_comments'] ? true : false;
            $metadata['views'] = 'true' != $instance['is_hide_views'] ? true : false;
            $metadata['likes'] = 'true' != $instance['is_hide_likes'] ? true : false;
            while ($posts->have_posts()) {
                $posts->the_post();
                $post_id = get_the_ID();
                $post_title = get_the_title();
                $post_url = get_permalink();
                ?>
                    <div <?php 
                post_class('item');
                ?>
>

                        <?php 
                if (has_category()) {
                    ?>
                            <h5 class="post-cat">
                                <?php 
                    the_category(', ');
                    ?>
                            </h5>
                        <?php 
                }
                ?>

                        <?php 
                if ('true' != $instance['is_hide_title']) {
                    ?>
                                        
                            <h4 class="post-title"><a href="<?php 
                    echo $post_url;
                    ?>
"><?php 
                    echo $post_title;
                    ?>
</a></h4>
                        <?php 
                }
                ?>

                        <?php 
                if ('true' != $instance['is_hide_excerpt']) {
                    if ((int) $instance['excerpt_character_limit'] > 0) {
                        $excerpt = KopaUtil::substr($post->post_content, (int) $instance['excerpt_character_limit']);
                        echo $excerpt ? sprintf('<p>%s</p>', $excerpt) : '';
                    } else {
                        the_excerpt();
                    }
                }
                ?>


                        <?php 
                if ($metadata['date'] || $metadata['comments'] || $metadata['views'] || $metadata['likes']) {
                    ?>
                            <footer>
                                <ul class="kp-meta-post list-inline">    
                                    <?php 
                    $is_metadata_first = true;
                    foreach ($metadata as $key => $val) {
                        if ($val) {
                            $class = $is_metadata_first ? 'metadata-first' : '';
                            $is_metadata_first = false;
                            switch ($key) {
                                case 'date':
                                    printf('<li class="%s">%s<span>%s</span></li>', $class, KopaIcon::getIconDatetime(), get_the_date());
                                    break;
                                case 'comments':
                                    ?>
                                                    <li class="<?php 
                                    echo $class;
                                    ?>
"><?php 
                                    echo KopaIcon::getIconComment();
                                    ?>
<span><?php 
                                    comments_popup_link(__('No Comment', kopa_get_domain()), __('1 Comment', kopa_get_domain()), __('% Comments', kopa_get_domain()), '', __('0 Comment', kopa_get_domain()));
                                    ?>
</span></li>                                            
                                                    <?php 
                                    break;
                                case 'views':
                                    printf('<li class="%s">%s<span>%s</span></li>', $class, KopaIcon::getIconView(), KopaUtil::get_views($post_id, true));
                                    break;
                                case 'likes':
                                    printf('<li class="%s">%s</li>', $class, KopaUtil::kopa_get_like_button($post_id, true));
                                    break;
                            }
                        }
                    }
                    ?>
                                   
                                </ul> 
                            </footer>
                        <?php 
                }
                ?>

                    </div>
                    <?php 
            }
            ?>
                
            </div>
            <?php 
        } else {
            _e('Posts not found. Pleae config this widget again!', kopa_get_domain());
        }
        wp_reset_postdata();
        echo $after_widget;
    }
    public function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
        echo $before_widget;
        if (!empty($title)) {
            echo $before_title . $title . $after_title;
        }
        $query = $this->build_query($instance);
        $posts = new WP_Query($query);
        if ($posts->have_posts()) {
            global $post;
            $max = (int) $instance['posts_per_page'];
            $limit_carousel = $max >= 3 ? $posts->post_count - 2 : -1;
            $loop_index = 0;
            $metadata = array();
            $metadata['date'] = 'true' != $instance['is_hide_created_date'] ? true : false;
            $metadata['comments'] = 'true' != $instance['is_hide_comments'] ? true : false;
            $metadata['views'] = 'true' != $instance['is_hide_views'] ? true : false;
            $metadata['likes'] = 'true' != $instance['is_hide_likes'] ? true : false;
            ?>
            <div class="widget-content clearfix">
                <div class="owl-carousel pull-left">
                    <?php 
            while ($posts->have_posts()) {
                $posts->the_post();
                $post_id = get_the_ID();
                $post_title = get_the_title();
                $post_url = get_permalink();
                if (-1 != $limit_carousel && $limit_carousel == $loop_index) {
                    break;
                } else {
                    $loop_index++;
                }
                ?>
     
                        <div <?php 
                post_class('item');
                ?>
>
                            <?php 
                if (has_post_thumbnail()) {
                    $image_croped = KopaImage::get_post_image_src($post_id, 'size_04');
                    ?>
                                <a href="<?php 
                    echo $post_url;
                    ?>
"><img src="<?php 
                    echo $image_croped;
                    ?>
" alt="<?php 
                    echo $post_title;
                    ?>
"/></a>
                                <?php 
                }
                ?>

                            <?php 
                if ('true' != $instance['is_hide_title'] || 'true' != $instance['is_hide_excerpt']) {
                    ?>
                                <div class="kp-caption">
                                    <?php 
                    if ('true' != $instance['is_hide_title']) {
                        ?>
                                        <?php 
                        $h4_class = 'true' != $instance['is_hide_excerpt'] ? '' : 'hide_excerpt';
                        ?>
                                        <h4 class="post-title <?php 
                        echo $h4_class;
                        ?>
"><a href="<?php 
                        echo $post_url;
                        ?>
"><?php 
                        echo $post_title;
                        ?>
</a></h4>
                                    <?php 
                    }
                    ?>

                                    <?php 
                    if ('true' != $instance['is_hide_excerpt']) {
                        if ((int) $instance['excerpt_character_limit'] > 0) {
                            $excerpt = KopaUtil::substr($post->post_content, (int) $instance['excerpt_character_limit']);
                            echo $excerpt ? sprintf('<p>%s</p>', $excerpt) : '';
                        } else {
                            the_excerpt();
                        }
                    }
                    ?>
                                
                                </div>
                            <?php 
                }
                ?>

                            <?php 
                if ($metadata['date'] || $metadata['comments'] || $metadata['views'] || $metadata['likes']) {
                    ?>
                                <footer>
                                    <ul class="kp-meta-post list-inline">    
                                        <?php 
                    $is_metadata_first = true;
                    foreach ($metadata as $key => $val) {
                        if ($val) {
                            $class = $is_metadata_first ? 'metadata-first' : '';
                            $is_metadata_first = false;
                            switch ($key) {
                                case 'date':
                                    printf('<li class="%s">%s<span>%s</span></li>', $class, KopaIcon::getIconDatetime(), get_the_date());
                                    break;
                                case 'comments':
                                    ?>
                                                        <li class="<?php 
                                    echo $class;
                                    ?>
"><?php 
                                    echo KopaIcon::getIconComment();
                                    ?>
<span><?php 
                                    comments_popup_link(__('No Comment', kopa_get_domain()), __('1 Comment', kopa_get_domain()), __('% Comments', kopa_get_domain()), '', __('0 Comment', kopa_get_domain()));
                                    ?>
</span></li>                                            
                                                        <?php 
                                    break;
                                case 'views':
                                    printf('<li class="%s">%s<span>%s</span></li>', $class, KopaIcon::getIconView(), KopaUtil::get_views($post_id, true));
                                    break;
                                case 'likes':
                                    printf('<li class="%s">%s</li>', $class, KopaUtil::kopa_get_like_button($post_id, true));
                                    break;
                            }
                        }
                    }
                    ?>
                                   
                                    </ul> 
                                </footer>
                            <?php 
                }
                ?>

                        </div>
                        <?php 
            }
            wp_reset_postdata();
            ?>
                </div>

                <?php 
            if (-1 != $limit_carousel) {
                ?>
                    <ul class="list-content pull-left list-unstyled">
                        <?php 
                $sub_posts = new WP_Query($query);
                $sub_loop_index = 0;
                while ($sub_posts->have_posts()) {
                    $sub_posts->the_post();
                    $post_id = get_the_ID();
                    $post_title = get_the_title();
                    $post_url = get_permalink();
                    if ($sub_loop_index >= $limit_carousel) {
                        ?>
     
                                <li>
                                    <?php 
                        if (has_post_thumbnail()) {
                            $image_croped = KopaImage::get_post_image_src($post_id, 'size_02');
                            ?>
                                        <a href="<?php 
                            echo $post_url;
                            ?>
"><img src="<?php 
                            echo $image_croped;
                            ?>
" alt="<?php 
                            echo $post_title;
                            ?>
"/></a>
                                        <?php 
                        }
                        ?>

                                    <?php 
                        if ('true' != $instance['is_hide_title']) {
                            ?>
                                        <h4 class="post-title"><a href="<?php 
                            echo $post_url;
                            ?>
"><?php 
                            echo $post_title;
                            ?>
</a></h4>
                                    <?php 
                        }
                        ?>

                                    <?php 
                        if ($metadata['date'] || $metadata['comments'] || $metadata['views'] || $metadata['likes']) {
                            ?>
                                        <footer>
                                            <ul class="kp-meta-post list-inline">    
                                                <?php 
                            $is_metadata_first = true;
                            foreach ($metadata as $key => $val) {
                                if ($val) {
                                    $class = $is_metadata_first ? 'metadata-first' : '';
                                    $is_metadata_first = false;
                                    switch ($key) {
                                        case 'date':
                                            printf('<li class="%s">%s<span>%s</span></li>', $class, KopaIcon::getIconDatetime(), get_the_date());
                                            break;
                                        case 'comments':
                                            ?>
                                                                <li class="<?php 
                                            echo $class;
                                            ?>
"><?php 
                                            echo KopaIcon::getIconComment();
                                            ?>
<span><?php 
                                            comments_popup_link(__('No Comment', kopa_get_domain()), __('1 Comment', kopa_get_domain()), __('% Comments', kopa_get_domain()), '', __('0 Comment', kopa_get_domain()));
                                            ?>
</span></li>                                            
                                                                <?php 
                                            break;
                                    }
                                }
                            }
                            ?>
                                   
                                            </ul> 
                                        </footer>
                                    <?php 
                        }
                        ?>

                                </li>
                                <?php 
                    }
                    $sub_loop_index++;
                }
                wp_reset_postdata();
                ?>
                    </ul>
                <?php 
            }
            ?>
            </div>                      
            <?php 
        } else {
            _e('Posts not found. Pleae config this widget again!', kopa_get_domain());
        }
        echo $after_widget;
    }
Пример #7
0
/**
 * @package Kopa
 * @subpackage Core
 * @author thethangtran <*****@*****.**>
 * @since 1.0.0
 */
function kopa_get_related_posts()
{
    if (is_single()) {
        $get_by = get_option('post_related_posts_get_by', 'post_tag');
        $limit = (int) KopaOptions::get_option('post_related_posts_limit', 4);
        if ($limit > 0) {
            global $post;
            $taxs = array();
            if ('category' == $get_by) {
                $cats = get_the_category($post->ID);
                if ($cats) {
                    $ids = array();
                    foreach ($cats as $cat) {
                        $ids[] = $cat->term_id;
                    }
                    $taxs[] = array('taxonomy' => 'category', 'field' => 'id', 'terms' => $ids);
                }
            } else {
                $tags = get_the_tags($post->ID);
                if ($tags) {
                    $ids = array();
                    foreach ($tags as $tag) {
                        $ids[] = $tag->term_id;
                    }
                    $taxs[] = array('taxonomy' => 'post_tag', 'field' => 'id', 'terms' => $ids);
                }
            }
            if ($taxs) {
                $related_args = array('tax_query' => $taxs, 'post__not_in' => array($post->ID), 'posts_per_page' => $limit);
                $related_posts = new WP_Query($related_args);
                if ($related_posts->have_posts()) {
                    ?>
                    <div class="related-article">
                        <h3 class="widget-title"><span><span><span><?php 
                    _e('Related articles', kopa_get_domain());
                    ?>
</span></span></span></h3>
                        <div class="widget-content">
                            <div class="owl-carousel owl-carousel-related">
                                <?php 
                    while ($related_posts->have_posts()) {
                        $related_posts->the_post();
                        $post_id = get_the_ID();
                        $post_url = get_permalink();
                        $post_title = get_the_title();
                        ?>
                                    <div <?php 
                        post_class('item');
                        ?>
>
                                        <?php 
                        if (has_post_thumbnail()) {
                            $image_croped = KopaImage::get_post_image_src($post_id, 'size_08');
                            ?>
                                            <a href="<?php 
                            echo $post_url;
                            ?>
"><img src="<?php 
                            echo $image_croped;
                            ?>
" alt="<?php 
                            echo $post_title;
                            ?>
" /></a>
                                            <?php 
                        }
                        ?>
                                        <div class="kp-caption">
                                            <h4 class="post-title"><a href="<?php 
                        echo $post_url;
                        ?>
"><?php 
                        echo $post_title;
                        ?>
</a></h4>

                                            <ul class="kp-meta-post list-inline">
                                                <li><?php 
                        echo KopaIcon::getIconDatetime();
                        ?>
<span><?php 
                        echo get_the_date();
                        ?>
</span></li>                                                
                                                <li><?php 
                        echo KopaIcon::getIconComment();
                        ?>
<span><?php 
                        comments_popup_link(__('No Comment', kopa_get_domain()), __('1 Comment', kopa_get_domain()), __('% Comments', kopa_get_domain()), '', __('0 Comment', kopa_get_domain()));
                        ?>
</span></li>
                                            </ul>

                                            <span class="kp-meta-post"><?php 
                        echo get_the_date();
                        ?>
</span>
                                        </div>
                                    </div>
                                    <?php 
                    }
                    ?>
                            </div>
                        </div>
                    </div>
                    <?php 
                }
                wp_reset_postdata();
            }
        }
    }
}
Пример #8
0
    public static function get_html($query, $params, $paged = 1, $orderby = 'date')
    {
        global $post;
        $query['paged'] = (int) $paged;
        $posts = new WP_Query($query);
        while ($posts->have_posts()) {
            $posts->the_post();
            $post_id = get_the_ID();
            $post_title = get_the_title();
            $post_url = get_permalink();
            $post_format = get_post_format();
            ?>
            <div class="item">
                <?php 
            if (has_post_thumbnail()) {
                $image_croped = KopaImage::get_post_image_src($post_id, 'size_07');
                ?>
                    <figure>
                        <a href="<?php 
                echo $post_url;
                ?>
" class="pull-left">
                            <img src="<?php 
                echo $image_croped;
                ?>
" alt="">                                            
                            <span><?php 
                echo KopaIcon::getIconPostFormat($post_format);
                ?>
</span>
                        </a>                            
                    </figure>
                    <?php 
            }
            ?>

                <div class="item-content">
                    <?php 
            if (!$params['is_hide_title']) {
                ?>
                        <h4 class="post-title"><a href="<?php 
                echo $post_url;
                ?>
"><?php 
                echo $post_title;
                ?>
</a></h4>
                    <?php 
            }
            ?>
                   


                    <?php 
            if (!$params['is_hide_excerpt']) {
                if ((int) $params['excerpt_character_limit'] > 0) {
                    $excerpt = KopaUtil::substr($post->post_content, (int) $params['excerpt_character_limit']);
                    echo $excerpt ? sprintf('<p>%s</p>', $excerpt) : '';
                } else {
                    the_excerpt();
                }
            }
            ?>

                </div>

                <ul class="kp-meta-post bottom list-inline">
                    <li class="metadata-first"><?php 
            echo KopaIcon::getIconDatetime();
            ?>
<span><?php 
            echo get_the_date();
            ?>
</span></li>

                    <?php 
            switch ($orderby) {
                case 'views':
                    printf('<li>%s<span>%s</span></li>', KopaIcon::getIconView(), KopaUtil::get_views($post_id, true));
                    break;
                case 'likes':
                    printf('<li>%s</li>', KopaUtil::kopa_get_like_button($post_id, true));
                    break;
                default:
                    ?>
                            <li><?php 
                    echo KopaIcon::getIconComment();
                    comments_popup_link(__('No Comment', kopa_get_domain()), __('1 Comment', kopa_get_domain()), __('% Comments', kopa_get_domain()), '', __('0 Comment', kopa_get_domain()));
                    ?>
</li>
                            <?php 
                    break;
            }
            ?>
 
                </ul>

            </div>
            <?php 
        }
        wp_reset_postdata();
    }