Exemplo n.º 1
0
    function widget($args, $instance)
    {
        extract($args);
        $posts = $instance['posts'];
        $comments = $instance['comments'];
        $tags_count = $instance['tags'];
        $show_popular_posts = isset($instance['show_popular_posts']) ? 'true' : 'false';
        $show_recent_posts = isset($instance['show_recent_posts']) ? 'true' : 'false';
        $show_comments = isset($instance['show_comments']) ? 'true' : 'false';
        $show_tags = isset($instance['show_tags']) ? 'true' : 'false';
        $extra_class = !empty($instance['extra_class']) ? $instance['extra_class'] : "";
        // no 'class' attribute - add one with the value of width
        if (strpos($before_widget, 'class') === false) {
            $before_widget = str_replace('>', 'class="' . $extra_class . '"', $before_widget);
        } else {
            $before_widget = str_replace('class="', 'class="' . $extra_class . ' ', $before_widget);
        }
        echo '' . $before_widget;
        ?>
        <div class="tab-holder">
            <div class="tab-hold tabs-wrapper">
                <ul id="tabs" class="nav nav-tabs clearfix">
                    <?php 
        if ($show_popular_posts == 'true') {
            ?>
                        <li class="active"><a href="#tab1" data-toggle="tab"><?php 
            echo __('Popular', 'fptcity');
            ?>
</a></li>
                    <?php 
        }
        ?>
                    <?php 
        if ($show_recent_posts == 'true') {
            ?>
                        <li><a href="#tab2" data-toggle="tab"><?php 
            echo __('Recent', 'fptcity');
            ?>
</a></li>
                    <?php 
        }
        ?>
                    <?php 
        if ($show_comments == 'true') {
            ?>
                        <li><a href="#tab3" data-toggle="tab"><?php 
            echo __('Comments', 'fptcity');
            ?>
</a></li>
                    <?php 
        }
        ?>
                </ul>
                <div class="tab-content">
                    <?php 
        if ($show_popular_posts == 'true') {
            ?>
                        <div id="tab1" class="tab-pane active">
                            <?php 
            $popular_posts = new WP_Query('showposts=' . $posts . '&orderby=comment_count&order=DESC');
            if ($popular_posts->have_posts()) {
                ?>
                                <ul class="news-list zo-popular">
                                    <?php 
                while ($popular_posts->have_posts()) {
                    $popular_posts->the_post();
                    ?>
                                        <li>
                                            <?php 
                    if (has_post_thumbnail()) {
                        ?>
                                            <div class="zo-image">
                                                <a class="post-featured-img" href="<?php 
                        the_permalink();
                        ?>
">
                                                   <?php 
                        the_post_thumbnail('thumbnail');
                        ?>
                                                </a>
                                            </div>
                                            <?php 
                    }
                    ?>

                                            <div class="zo-details">
                                                <h4><?php 
                    the_title();
                    ?>
</h4>
                                                <?php 
                    the_category(' / ');
                    ?>
                                            </div>
                                        </li>
                                    <?php 
                }
                ?>
                                </ul>
                            <?php 
            }
            ?>
                        </div>
                    <?php 
        }
        ?>
                    <?php 
        if ($show_recent_posts == 'true') {
            ?>
                        <div id="tab2" class="tab-pane">
                            <?php 
            $recent_posts = new WP_Query('showposts=' . $posts);
            if ($recent_posts->have_posts()) {
                ?>
                                <ul class="news-list zo-popular">
                                    <?php 
                while ($recent_posts->have_posts()) {
                    $recent_posts->the_post();
                    ?>
                                        <li>
                                            <?php 
                    if (has_post_thumbnail()) {
                        ?>
                                            <div class="zo-image">
                                                <a class="post-featured-img" href="<?php 
                        the_permalink();
                        ?>
">
                                                   <?php 
                        the_post_thumbnail('thumbnail');
                        ?>
                                                </a>
                                            </div>
                                            <?php 
                    }
                    ?>

                                            <div class="zo-details table-cell">
                                                <h4><?php 
                    the_title();
                    ?>
</h4>
                                                <?php 
                    the_category(' / ');
                    ?>
                                            </div>
                                        </li>
                                    <?php 
                }
                ?>
                                </ul>
                            <?php 
            }
            ?>
                        </div>
                    <?php 
        }
        ?>
                    <?php 
        if ($show_comments == 'true') {
            ?>
                        <div id="tab3" class="tab-pane">
                            <ul class="news-list sh-list-comment">
                                <?php 
            global $wpdb;
            $number = $instance['comments'];
            $recent_comments = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_author_email, comment_date_gmt, comment_approved, comment_type, comment_author_url, SUBSTRING(comment_content,1,110) AS com_excerpt FROM {$wpdb->comments} LEFT OUTER JOIN {$wpdb->posts} ON ({$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT {$number}";
            $the_comments = $wpdb->get_results($recent_comments);
            foreach ($the_comments as $comment) {
                ?>
                                    <li>
                                        <div class="image table-cell">
                                            <a>
                                                <?php 
                echo get_avatar($comment->comment_author_email, '32');
                ?>
                                            </a>
                                        </div>
                                        <div class="post-holder table-cell">
                                            <p><?php 
                echo strip_tags($comment->comment_author);
                ?>
 says:</p>
                                            <div class="meta">
                                                <a class="comment-text-side" href="<?php 
                echo get_permalink($comment->ID);
                ?>
#comment-<?php 
                echo '' . $comment->comment_ID;
                ?>
" title="<?php 
                echo strip_tags($comment->comment_author);
                ?>
 on <?php 
                echo '' . $comment->post_title;
                ?>
"><?php 
                echo zo_limit_words(strip_tags($comment->com_excerpt), 12);
                ?>
...</a>
                                            </div>
                                        </div>
                                    </li>
                                <?php 
            }
            ?>
                            </ul>
                        </div>
                    <?php 
        }
        ?>
                </div>
            </div>
        </div>
        <?php 
        echo '' . $after_widget;
    }
Exemplo n.º 2
0
    function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts', THEMENAME) : $instance['title'], $instance, $this->id_base);
        $show_date = (int) $instance['show_date'];
        $show_decs = (int) $instance['show_decs'];
        $number = (int) $instance['number'];
        echo balanceTags($before_widget);
        if ($title) {
            echo balanceTags($before_title . $title . $after_title);
        }
        $sticky = get_option('sticky_posts');
        $args = array('posts_per_page' => $number, 'post_type' => 'post', 'post_status' => 'publish', 'post__not_in' => $sticky, 'orderby' => 'date', 'order' => 'DESC', 'paged' => 1);
        $wp_query = new WP_Query($args);
        $extra_class = !empty($instance['extra_class']) ? $instance['extra_class'] : "";
        // no 'class' attribute - add one with the value of width
        if (strpos($before_widget, 'class') === false) {
            $before_widget = str_replace('>', 'class="' . $extra_class . '"', $before_widget);
        } else {
            $before_widget = str_replace('class="', 'class="' . $extra_class . ' ', $before_widget);
        }
        echo '' . $before_widget;
        ?>
        <?php 
        if ($wp_query->have_posts()) {
            ?>
                <div class="zo-recent-post">
                    <ul class="zo-recent-post-wrapper">
                        <?php 
            while ($wp_query->have_posts()) {
                $wp_query->the_post();
                ?>
                            <li>
                                <?php 
                if (has_post_thumbnail()) {
                    ?>
                                <div class="zo-recent-media">  
                                   <div class="image">
                                       <a class="post-featured-img" href="<?php 
                    the_permalink();
                    ?>
">
                                          <?php 
                    the_post_thumbnail(array(50, 50));
                    ?>
                                       </a>
                                    </div>     
                                 </div>
                                <?php 
                }
                ?>
 
                                <div class="zo-recent-details <?php 
                if (has_post_thumbnail() == '') {
                    echo 'no-image';
                }
                ?>
">
                                    <h3 class="title"><a href="<?php 
                the_permalink();
                ?>
"><?php 
                the_title();
                ?>
</a></h3>
                                    <?php 
                if ($show_date) {
                    ?>
                                    <div class="date">  
                                    <span><?php 
                    echo get_the_date('M d Y');
                    ?>
</span>
                                    <span class="author">by <?php 
                    echo get_the_author();
                    ?>
</span>
                                    </div>
                                    <?php 
                }
                ?>
   
                                    <?php 
                if ($show_decs) {
                    ?>
                                        <div class="description"><?php 
                    echo zo_limit_words(strip_tags(get_the_excerpt()), 10) . "...";
                    ?>
</div>
                                    <?php 
                }
                ?>
                                </div>
                            </li>
                        <?php 
            }
            ?>
                    </ul>
                </div>
            <?php 
        } else {
            ?>
                <span class="notfound">No post found!</span>
            <?php 
        }
        echo '' . $after_widget;
        wp_reset_postdata();
    }