public function widget($args, $instance)
 {
     $title = apply_filters('widget_title', $instance['title']);
     echo $args['before_widget'];
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     $category = $instance['category'];
     $unserialized_categories = unserialize($category);
     $cat_string = is_array($unserialized_categories) ? join(',', $unserialized_categories) : '';
     $max_posts = (int) $instance['max_posts'];
     $autoheight = (int) $instance['autoheight'];
     $autoplay = (int) $instance['autoplay'];
     // the query
     $q = new WP_Query(array('orderby' => 'date', 'posts_per_page' => $max_posts > 0 && $max_posts <= 10 ? $max_posts : 5, 'category__in' => $unserialized_categories, 'meta_key' => '_thumbnail_id'));
     $list = '<div class="bw-widget-slider-holder">';
     $list .= '<ul class="bw-widget-slider ' . ($autoplay ? 'auto-play' : '') . '" ' . ($autoplay ? 'data-speed="3000"' : '') . '>';
     while ($q->have_posts()) {
         $q->the_post();
         $size = $autoheight ? 'bw_350' : 'bw_350x300';
         if (Bw::get_option('enable_lazy_image')) {
             $thumbnail = '<img class="lazy" data-src="' . Bw::get_image_src($size) . '" src="' . Bw::empty_img('350x300') . '" alt="">';
         } else {
             $thumbnail = '<img src="' . Bw::get_image_src($size) . '" alt="">';
         }
         $list .= "<li>\n\t\t\t\t<a class='image' href='" . get_permalink() . "'>\n\t\t\t\t\t{$thumbnail}\n\t\t\t\t</a>\n\t\t\t\t<div class='box'>\n\t\t\t\t\t<h4 class='bb'><a href='" . get_permalink() . "' title='" . get_the_title() . "'>" . get_the_title() . "</a></h4>\n\t\t\t\t</div>\n\t\t\t</li>";
     }
     wp_reset_query();
     $list .= "</ul>";
     $list .= "</div>";
     echo $list;
     echo $args['after_widget'];
 }
 function widget($args, $instance)
 {
     global $comments, $comment;
     $cache = wp_cache_get('widget_recent_comments', 'widget');
     if (!is_array($cache)) {
         $cache = array();
     }
     if (!isset($args['widget_id'])) {
         $args['widget_id'] = $this->id;
     }
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return;
     }
     extract($args, EXTR_SKIP);
     $output = '';
     $title = !empty($instance['title']) ? $instance['title'] : __('Recent Comments');
     $title = apply_filters('widget_title', $title, $instance, $this->id_base);
     $number = !empty($instance['number']) ? absint($instance['number']) : 5;
     if (!$number) {
         $number = 5;
     }
     $comments = get_comments(apply_filters('widget_comments_args', array('number' => $number, 'status' => 'approve', 'post_status' => 'publish')));
     $output .= $before_widget;
     if ($title) {
         $output .= $before_title . $title . $after_title;
     }
     $output .= '<ul id="recentcomments" class="bw-sidebar-posts">';
     if ($comments) {
         // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
         $post_ids = array_unique(wp_list_pluck($comments, 'comment_post_ID'));
         _prime_post_caches($post_ids, strpos(get_option('permalink_structure'), '%category%'), false);
         foreach ((array) $comments as $comment) {
             if (Bw::get_option('enable_lazy_image')) {
                 $bw_image = "<img class='lazy' data-src='" . get_avatar_url($comment->user_id) . "' src='" . Bw::empty_img() . "' alt='' >";
             } else {
                 $bw_image = "<img src='" . get_avatar_url($comment->user_id) . "' alt='' >";
             }
             $output .= '<li class="recentcomments">';
             $output .= '<div class="thumb"><a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . $bw_image . '</a></div>';
             $output .= '<div class="cont"><a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . get_comment_author_link() . '</a>';
             $output .= '<p>' . Bw::truncate($comment->comment_content, 7) . '</p></div>';
             $output .= '</li>';
         }
     }
     $output .= '</ul>';
     $output .= $after_widget;
     echo $output;
     $cache[$args['widget_id']] = $output;
     wp_cache_set('widget_recent_comments', $cache, 'widget');
 }
Esempio n. 3
0
    if (isset($wp_query->query_vars['thumbnail_size'])) {
        $thumbsize = $wp_query->query_vars['thumbnail_size'];
    }
    ?>
				
					<div class="image-hide">
						<div class="image-wrap">
							
							<?php 
    if (Bw::get_option('enable_lazy_image')) {
        ?>
								<img class="lazy" data-src="<?php 
        echo Bw::get_image_src($thumbsize);
        ?>
" src="<?php 
        echo Bw::empty_img();
        ?>
" alt="<?php 
        the_title();
        ?>
" >
							<?php 
    } else {
        ?>
								<img src="<?php 
        echo Bw::get_image_src($thumbsize);
        ?>
" alt="<?php 
        the_title();
        ?>
" >
    function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts', BW_THEME) : $instance['title'], $instance, $this->id_base);
        if (empty($instance['number']) || !($number = absint($instance['number']))) {
            $number = 10;
        }
        $r = new WP_Query(apply_filters('widget_posts_args', array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true)));
        if ($r->have_posts()) {
            echo $before_widget;
            if ($title) {
                echo $before_title . $title . $after_title;
            }
            ?>
			<ul class="bw-sidebar-posts">
				<?php 
            while ($r->have_posts()) {
                $r->the_post();
                ?>
				
				<li class="<?php 
                if (!has_post_thumbnail()) {
                    echo 'auto';
                }
                ?>
">
					
					<?php 
                if (has_post_thumbnail()) {
                    ?>
					<div class="thumb">
						<a href="<?php 
                    the_permalink();
                    ?>
" title="<?php 
                    the_title();
                    ?>
">
							
							<?php 
                    if (Bw::get_option('enable_lazy_image')) {
                        ?>
								<img class="lazy" data-src="<?php 
                        echo Bw::get_image_src('thumbnail');
                        ?>
" src="<?php 
                        echo Bw::empty_img();
                        ?>
" alt="" >
							<?php 
                    } else {
                        ?>
								<img src="<?php 
                        echo Bw::get_image_src('thumbnail');
                        ?>
" alt="" >
							<?php 
                    }
                    ?>
							
						</a>
					</div>
					<?php 
                }
                ?>
					
					<div class="cont <?php 
                if (!has_post_thumbnail()) {
                    echo ' no-thumb';
                }
                ?>
">
						<a href="<?php 
                the_permalink();
                ?>
" title="<?php 
                the_title();
                ?>
">
							<?php 
                the_title();
                ?>
						</a>
						<p><?php 
                echo Bw::truncate(get_the_excerpt(), 6);
                ?>
</p>
					</div>
					
				</li>
				<?php 
            }
            ?>
			</ul>
			 
			<?php 
            echo $after_widget;
            wp_reset_postdata();
        }
    }
    public function query_by_id($time, $instance)
    {
        global $wpdb;
        global $post;
        $limit = (int) $instance['max_posts'] > 0 && (int) $instance['max_posts'] <= 10 ? (int) $instance['max_posts'] : 5;
        //$categories = unserialize( $instance['category'] );
        //$joined_categories = is_array( $categories ) ? join( ',', $categories ) : null;
        if ($time !== 'bw-all-time' && $time > 0) {
            $joins = "\r\n\t\t\t\tLEFT JOIN {$wpdb->term_relationships} ON({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)\r\n\t\t\t\tLEFT JOIN {$wpdb->term_taxonomy} ON({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id)\r\n\t\t\t\tLEFT JOIN {$wpdb->terms} ON({$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id)\r\n\t\t\t";
            $where = "\r\n\t\t\t\tAND {$wpdb->term_taxonomy}.taxonomy = 'category'\r\n\t\t\t\tAND {$wpdb->terms}.term_id  = '" . $time . "'\r\n\t\t\t";
        } else {
            $joins = '';
            $where = '';
        }
        $querystr = "\r\n\t\t\t\r\n\t\t\tSELECT *, CAST({$wpdb->posts}.post_date AS DATE) as bw_date\r\n\t\t\tFROM {$wpdb->posts}\r\n\t\t\tLEFT JOIN {$wpdb->postmeta} ON({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)\r\n\t\t\t\t\r\n\t\t\t\t" . $joins . "\r\n\t\t\t\r\n\t\t\tWHERE {$wpdb->postmeta}.meta_key = 'post_views_count'\r\n\t\t\tAND {$wpdb->posts}.post_status = 'publish'\r\n\t\t\tAND {$wpdb->posts}.post_date < NOW()\r\n\t\t\tAND {$wpdb->posts}.post_type = 'post'\r\n\t\t\t\t\r\n\t\t\t\t" . $where . "\r\n\t\t\t\r\n\t\t\tORDER BY bw_date desc, {$wpdb->postmeta}.meta_value+0 desc\r\n\t\t\t\r\n\t\t\tLIMIT " . $limit . "\r\n\t\t\t\r\n\t\t";
        $pageposts = $wpdb->get_results($querystr, object);
        $c = 1;
        echo '<ul class="bw-sidebar-posts ' . trim($time) . '">';
        foreach ($pageposts as $post) {
            setup_postdata($post);
            ?>
<li>
				
				<!--div class="position">
					<?php 
            echo sprintf("%02d", $c);
            ?>
				</div-->
				
				<?php 
            if (has_post_thumbnail()) {
                ?>
				<div class="thumb">
					<a href="<?php 
                the_permalink();
                ?>
" title="<?php 
                the_title();
                ?>
">
						
						<?php 
                if (Bw::get_option('enable_lazy_image')) {
                    ?>
							<img class="lazy" data-src="<?php 
                    echo Bw::get_image_src('thumbnail');
                    ?>
" src="<?php 
                    echo Bw::empty_img();
                    ?>
" alt="" >
						<?php 
                } else {
                    ?>
							<img src="<?php 
                    echo Bw::get_image_src('thumbnail');
                    ?>
" alt="" >
						<?php 
                }
                ?>
						
					</a>
				</div>
				<?php 
            }
            ?>
				
				<div class="cont <?php 
            if (!has_post_thumbnail()) {
                echo ' no-thumb';
            }
            ?>
">
					<a href="<?php 
            the_permalink();
            ?>
" title="<?php 
            the_title();
            ?>
">
						<?php 
            the_title();
            ?>
					</a>
					<p><?php 
            echo Bw::truncate(get_the_excerpt(), 7);
            ?>
</p>
				</div>
				
			</li><?php 
            $c++;
        }
        wp_reset_postdata();
        echo '</ul>';
    }