/**
     * How to display the widget on the screen.
     */
    function widget($args, $instance)
    {
        extract($args);
        global $wpdb, $period_posts;
        $time_id = rand();
        /* Our variables from the widget settings. */
        $title = $instance['title'];
        $num_posts = $instance['num_posts'];
        $period_posts = $instance['period_posts'];
        $categories = $instance['categories'];
        $show_image = isset($instance['show_image']) ? 'true' : 'false';
        $show_related = isset($instance['show_related']) ? 'true' : 'false';
        $theme_orderby = $instance['theme_orderby'];
        $show_comments = isset($instance['show_comments']) ? 'true' : 'false';
        $show_date = isset($instance['show_date']) ? 'true' : 'false';
        /* Before widget (defined by themes). */
        echo $before_widget;
        /* Display the widget title if one was input (before and after defined by themes). */
        if ($title) {
            echo "\n<!-- START POPULAR POSTS WIDGET -->\n";
            echo $before_title . $title . $after_title;
        } else {
            echo "\n<!-- START POPULAR POSTS WIDGET -->\n";
        }
        ?>

		<?php 
        global $post, $ct_data;
        if ($period_posts > 0) {
            // Create a new filtering function that will add our where clause to the query
            if (!function_exists('ct_filter_where')) {
                function ct_filter_where($where = '')
                {
                    global $period_posts;
                    // posts in the last N days
                    $ct_days = '-' . $period_posts . ' days';
                    $where .= " AND post_date > '" . date('Y-m-d', strtotime($ct_days)) . "'";
                    return $where;
                }
            }
            if (!function_exists('ct_filter_orderby')) {
                function ct_filter_orderby($orderby = '')
                {
                    $orderby .= ", post_date DESC";
                    return $orderby;
                }
            }
            add_filter('posts_orderby', 'ct_filter_orderby');
            add_filter('posts_where', 'ct_filter_where');
        }
        if ($show_related == 'true') {
            //show related category
            $related_category = get_the_category($post->ID);
            $related_category_id = get_cat_ID($related_category[0]->cat_name);
            if ($theme_orderby == 'comments') {
                $popular_posts = new WP_Query(array('showposts' => $num_posts, 'orderby' => 'comment_count', 'cat' => $related_category_id, 'post__not_in' => array($post->ID), 'ignore_sticky_posts' => 1));
            } else {
                if ($theme_orderby == 'likes') {
                    $popular_posts = new WP_Query(array('showposts' => $num_posts, 'orderby' => 'meta_value_num', 'meta_key' => 'votes_count', 'cat' => $related_category_id, 'post__not_in' => array($post->ID), 'ignore_sticky_posts' => 1));
                } else {
                    if ($theme_orderby == 'views') {
                        $popular_posts = new WP_Query(array('showposts' => $num_posts, 'orderby' => 'meta_value_num', 'meta_key' => 'post_views_count', 'cat' => $related_category_id, 'post__not_in' => array($post->ID), 'ignore_sticky_posts' => 1));
                    }
                }
            }
        } else {
            if ($theme_orderby == 'comments') {
                $popular_posts = new WP_Query(array('showposts' => $num_posts, 'cat' => $categories, 'orderby' => 'comment_count', 'ignore_sticky_posts' => 1));
            } else {
                if ($theme_orderby == 'likes') {
                    $popular_posts = new WP_Query(array('showposts' => $num_posts, 'cat' => $categories, 'orderby' => 'meta_value_num', 'meta_key' => 'votes_count', 'ignore_sticky_posts' => 1));
                } else {
                    if ($theme_orderby == 'views') {
                        $popular_posts = new WP_Query(array('showposts' => $num_posts, 'cat' => $categories, 'orderby' => 'meta_value_num', 'meta_key' => 'post_views_count', 'ignore_sticky_posts' => 1));
                    }
                }
            }
        }
        if ($period_posts > 0) {
            remove_filter('posts_orderby', 'ct_filter_orderby');
            remove_filter('posts_where', 'ct_filter_where');
        }
        ?>

		<ul class="popular-posts-widget popular-widget-<?php 
        echo $time_id;
        ?>
">
			<?php 
        while ($popular_posts->have_posts()) {
            $popular_posts->the_post();
            ?>
				<li class="clearfix">
					<?php 
            if ($show_image == 'true') {
                if (has_post_thumbnail()) {
                    $image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'small-thumb');
                    if ($image[1] == 75 && $image[2] == 75) {
                        //if has generated thumb
                        ?>
								<div class="widget-post-small-thumb">
									<a href='<?php 
                        the_permalink();
                        ?>
' title='<?php 
                        _e('Permalink to ', 'color-theme-framework');
                        the_title();
                        ?>
'><img src="<?php 
                        echo $image[0];
                        ?>
" alt="<?php 
                        the_title();
                        ?>
" /></a>
								</div><!-- widget-post-small-thumb -->
							<?php 
                    } else {
                        // else use standard 150x150 thumb
                        $image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail');
                        ?>
								<div class="widget-post-small-thumb">
									<a href='<?php 
                        the_permalink();
                        ?>
' title='<?php 
                        _e('Permalink to ', 'color-theme-framework');
                        the_title();
                        ?>
'><img src="<?php 
                        echo $image[0];
                        ?>
" alt="<?php 
                        the_title();
                        ?>
" /></a>
								</div><!-- widget-post-small-thumb -->
							<?php 
                    }
                }
                //has_post_thumbnail
            }
            //show_image
            ?>

					<div class="post-title">
						<h5><a href='<?php 
            the_permalink();
            ?>
' title='<?php 
            _e('Permalink to ', 'color-theme-framework');
            the_title();
            ?>
'><?php 
            the_title();
            ?>
</a></h5>
					</div><!-- post-title -->

					<?php 
            if ($show_date == 'true' or $show_comments == 'true') {
                ?>
						<div class="entry-widget-date">							
							<?php 
                if ($show_date == 'true') {
                    echo esc_attr(get_the_date('M j, Y'));
                }
                ?>
 
								<?php 
                if ($show_comments == 'true') {
                    _e('&mdash;&nbsp;', 'color-theme-framework');
                    comments_popup_link(__('Leave a comment', 'color-theme-framework'), __('1 Comment', 'color-theme-framework'), __('% Comments', 'color-theme-framework'));
                }
                ?>
									
						</div> <!-- /entry-widget-date -->	
					<?php 
            }
            ?>

					<footer class="meta clearfix">
						<?php 
            ct_get_post_meta($post->ID, false, false, false);
            ?>
					</footer><!-- .meta -->
				</li>	
			<?php 
        }
        ?>
		</ul>

		<?php 
        /* After widget (defined by themes). */
        echo $after_widget;
        echo "\n<!-- END POPULAR POSTS WIDGET -->\n";
        // Restor original Query & Post Data
        wp_reset_query();
        wp_reset_postdata();
    }
    function widget($args, $instance)
    {
        extract($args);
        global $wpdb;
        $time_id = rand();
        /* Our variables from the widget settings. */
        $title = $instance['title'];
        $num_posts = $instance['num_posts'];
        $categories = $instance['categories'];
        $show_image = isset($instance['show_image']) ? 'true' : 'false';
        $show_related = isset($instance['show_related']) ? 'true' : 'false';
        $show_comments = isset($instance['show_comments']) ? 'true' : 'false';
        $show_date = isset($instance['show_date']) ? 'true' : 'false';
        /* Before widget (defined by themes). */
        echo $before_widget;
        /* Display the widget title if one was input (before and after defined by themes). */
        if ($title) {
            echo "\n<!-- START RECENT POSTS WIDGET -->\n";
            echo $before_title . $title . $after_title;
        } else {
            echo "\n<!-- START RECENT POSTS WIDGET -->\n";
        }
        ?>
			
		<?php 
        global $post, $ct_data;
        if ($show_related == 'true') {
            //show related category
            $related_category = get_the_category($post->ID);
            $related_category_id = get_cat_ID($related_category[0]->cat_name);
            $recent_posts = new WP_Query(array('showposts' => $num_posts, 'cat' => $related_category_id, 'post__not_in' => array($post->ID), 'ignore_sticky_posts' => 1));
        } else {
            $recent_posts = new WP_Query(array('showposts' => $num_posts, 'cat' => $categories, 'ignore_sticky_posts' => 1));
        }
        ?>

	<?php 
        if ($recent_posts->have_posts()) {
            ?>
		<ul class="recent-posts-widget recent-widget-<?php 
            echo $time_id;
            ?>
">
			<?php 
            while ($recent_posts->have_posts()) {
                $recent_posts->the_post();
                ?>
				<li class="clearfix">
					<?php 
                if ($show_image == 'true') {
                    if (has_post_thumbnail()) {
                        $image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'small-thumb');
                        if ($image[1] == 75 && $image[2] == 75) {
                            //if has generated thumb
                            ?>
								<div class="widget-post-small-thumb">
									<a href='<?php 
                            the_permalink();
                            ?>
' title='<?php 
                            _e('Permalink to ', 'color-theme-framework');
                            the_title();
                            ?>
'><img src="<?php 
                            echo $image[0];
                            ?>
" alt="<?php 
                            the_title();
                            ?>
" /></a>
								</div><!-- widget-post-small-thumb -->
							<?php 
                        } else {
                            // else use standard 150x150 thumb
                            $image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail');
                            ?>
								<div class="widget-post-small-thumb">
									<a href='<?php 
                            the_permalink();
                            ?>
' title='<?php 
                            _e('Permalink to ', 'color-theme-framework');
                            the_title();
                            ?>
'><img src="<?php 
                            echo $image[0];
                            ?>
" alt="<?php 
                            the_title();
                            ?>
" /></a>
								</div><!-- widget-post-small-thumb -->
							<?php 
                        }
                    }
                    //has_post_thumbnail
                }
                //show_image
                ?>

					<div class="post-title">
						<h5><a href='<?php 
                the_permalink();
                ?>
' title='<?php 
                _e('Permalink to ', 'color-theme-framework');
                the_title();
                ?>
'><?php 
                the_title();
                ?>
</a></h5>						
					</div><!-- post-title -->

					<?php 
                if ($show_date == 'true' or $show_comments == 'true') {
                    ?>
						<div class="entry-widget-date">							
							<?php 
                    if ($show_date == 'true') {
                        echo esc_attr(get_the_date('M j, Y'));
                    }
                    ?>
 
								<?php 
                    if ($show_comments == 'true') {
                        _e('&mdash;&nbsp;', 'color-theme-framework');
                        comments_popup_link(__('Leave a comment', 'color-theme-framework'), __('1 Comment', 'color-theme-framework'), __('% Comments', 'color-theme-framework'));
                    }
                    ?>
									
						</div> <!-- /entry-widget-date -->	
					<?php 
                }
                ?>

					<footer class="meta clearfix">
						<?php 
                ct_get_post_meta($post->ID, false, false, false);
                ?>
					</footer><!-- .meta -->
				</li>	
			<?php 
            }
            ?>
		</ul>
	<?php 
        } else {
            echo __('No posts were found for display', 'color-theme-framework');
        }
        ?>

		<?php 
        /* After widget (defined by themes). */
        echo $after_widget;
        echo "\n<!-- END RECENT POSTS WIDGET -->\n";
        // Restor original Query & Post Data
        wp_reset_query();
        wp_reset_postdata();
    }
Exemplo n.º 3
0
			</div> <!-- /entry-meta -->	
		<?php 
}
?>

		<div class="clear"></div>

		<?php 
// Displays a link to edit the current post, if a user is logged in and allowed to edit the post
edit_post_link(__('Edit', 'color-theme-framework'), '<span class="edit-link"><i class="icon-pencil"></i>', '</span>');
?>

		<?php 
$post_type = get_post_meta($post->ID, 'ct_mb_post_type', true);
if (empty($post_type)) {
    $post_type = 'standard_post';
}
if ($show_comments == 1 or $show_views == 1 or $show_likes == 1 or $post_type != 'standard_post') {
    echo '<div class="divider-1px-meta"></div>';
}
?>

		<footer class="entry-extra clearfix">
			<?php 
ct_get_post_meta($post->ID, $show_comments, $show_views, $show_likes);
?>
		</footer><!-- .entry-meta -->
	</div> <!-- /entry-post-content -->

	</div> <!-- /post-block -->  
</article><!-- #post-ID -->
    function widget($args, $instance)
    {
        extract($args);
        global $ct_options, $post;
        $title = $instance['title'];
        $categories = $instance['categories'];
        $posts = $instance['posts'];
        $show_likes = isset($instance['show_likes']) ? 'true' : 'false';
        $show_comments = isset($instance['show_comments']) ? 'true' : 'false';
        $show_views = isset($instance['show_views']) ? 'true' : 'false';
        $show_date = isset($instance['show_date']) ? 'true' : 'false';
        $show_related = isset($instance['show_related']) ? 'true' : 'false';
        $show_random = isset($instance['show_random']) ? 'true' : 'false';
        $animation_speed = $instance['animation_speed'];
        $slideshow_speed = $instance['slideshow_speed'];
        $slideshow = isset($instance['slideshow']) ? 'true' : 'false';
        $animation_type = $instance['animation_type'];
        ?>

		<?php 
        /* Before widget (defined by themes). */
        echo $before_widget;
        /* Display the widget title if one was input (before and after defined by themes). */
        if ($title) {
            echo "\n<!-- START SMALL SLIDER WIDGET -->\n";
            echo $before_title . $title . $after_title;
        } else {
            echo "\n<!-- START SMALL SLIDER WIDGET -->\n";
        }
        ?>
		
		<?php 
        $time_id = rand();
        $orderby = 'date';
        if ($show_random == 'true') {
            $orderby = 'rand';
        }
        if ($show_related == 'true') {
            //show related category
            $related_category = get_the_category($post->ID);
            $related_category_id = get_cat_ID($related_category[0]->cat_name);
            $slider_posts = new WP_Query(array('orderby' => $orderby, 'showposts' => $posts, 'post_type' => 'post', 'cat' => $related_category_id, 'post__not_in' => array($post->ID), 'ignore_sticky_posts' => 1));
        } else {
            $slider_posts = new WP_Query(array('orderby' => $orderby, 'showposts' => $posts, 'post_type' => 'post', 'cat' => $categories, 'ignore_sticky_posts' => 1));
        }
        if (!is_admin()) {
            /* Flex Slider */
            wp_register_script('flex-min-jquery', get_template_directory_uri() . '/js/jquery.flexslider-min.js', false, null, true);
            wp_enqueue_script('flex-min-jquery', array('jquery'));
        }
        if ($slider_posts->have_posts()) {
            ?>

		<script type="text/javascript">
		/* <![CDATA[ */
		jQuery.noConflict()(function($){
		  "use strict";
			$(window).load(function() {
				$(".slider-preloader").css("display","none");
					$('#slider-<?php 
            echo $time_id;
            ?>
').flexslider({
						animation:"<?php 
            echo $animation_type;
            ?>
",
						controlNav:false,
						animationLoop:true,
						slideshow:<?php 
            echo $slideshow;
            ?>
,
						smoothHeight:true,
						slideshowSpeed:<?php 
            echo $slideshow_speed;
            ?>
,
						animationSpeed:<?php 
            echo $animation_speed;
            ?>
,
					});
				});
		});
		/* ]]> */
		</script>

		<div id="slider-<?php 
            echo $time_id;
            ?>
" class="small-slider flex-main flexslider">
			<ul class="slides">

			<?php 
            while ($slider_posts->have_posts()) {
                $slider_posts->the_post();
                ?>
				<?php 
                if (has_post_thumbnail()) {
                    $image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'single-post-thumb-crop');
                    ?>
					<li>
						<a href="<?php 
                    the_permalink();
                    ?>
"><img src="<?php 
                    echo $image[0];
                    ?>
" alt="" /></a>
						
						<!-- title -->
						<div class="post-title">
							<h5><a href='<?php 
                    the_permalink();
                    ?>
' title='<?php 
                    _e('Permalink to ', 'color-theme-framework');
                    the_title();
                    ?>
'><?php 
                    the_title();
                    ?>
</a></h5>
						</div><!-- post-title -->

						<?php 
                    if ($show_date == 'true') {
                        ?>
							<div class="entry-date"><?php 
                        echo esc_attr(get_the_date('M j, Y'));
                        ?>
</div>
						<?php 
                    }
                    ?>
	

						<?php 
                    ct_excerpt_max_charlength(100);
                    ?>

						<div class="clear"></div>
						<div class="divider-1px-meta"></div>
						<footer class="entry-extra clearfix">
							<?php 
                    global $post;
                    if ($show_comments == 'true') {
                        $show_comments = 1;
                    }
                    if ($show_views == 'true') {
                        $show_views = 1;
                    }
                    if ($show_likes == 'true') {
                        $show_likes = 1;
                    }
                    ?>
							<?php 
                    ct_get_post_meta($post->ID, $show_comments, $show_views, $show_likes);
                    ?>
						</footer><!-- .meta -->
					</li>
				<?php 
                }
                ?>
			<?php 
            }
            ?>

			</ul><!-- slides -->
		</div><!-- slider -->
		
		<?php 
        } else {
            echo __('No related posts were found', 'color-theme-framework');
        }
        // Restor original Query & Post Data
        wp_reset_query();
        wp_reset_postdata();
        /* After widget (defined by themes). */
        echo $after_widget;
        echo "\n<!-- END SMALL SLIDER WIDGET -->\n";
    }