Exemplo n.º 1
0
    public function widget($args, $instance)
    {
        global $post, $road_opt;
        $title = apply_filters('widget_title', $instance['title']);
        // before and after widget arguments are defined by themes
        echo wp_kses($args['before_widget'], array('aside' => array('id' => array(), 'class' => array())));
        if (!empty($title)) {
            echo wp_kses($args['before_title'] . $title . $args['after_title'], array('aside' => array('id' => array(), 'class' => array()), 'h3' => array('class' => array()), 'span' => array('class' => array())));
        }
        switch ($instance['type']) {
            case 'recent_posts':
                $postargs = array('posts_per_page' => $instance['amount'], 'order' => 'DESC', 'orderby' => 'post_date');
                $postslist = get_posts($postargs);
                ?>
				<div class="recent-posts">
					<ul>
						<?php 
                foreach ($postslist as $post) {
                    setup_postdata($post);
                    ?>
 
							<li>
								<div class="post-wrapper">
									<div class="post-thumb">
										<a href="<?php 
                    the_permalink();
                    ?>
"><?php 
                    the_post_thumbnail(array(50, 50));
                    ?>
</a>
									</div>
									<div class="post-info">
										<h3 class="post-title"><a href="<?php 
                    the_permalink();
                    ?>
"><?php 
                    the_title();
                    ?>
</a></h3>
										<div class="post-date">
											<?php 
                    echo get_the_date();
                    ?>
										</div>
									</div>
								</div>
							</li>
						<?php 
                }
                ?>
					</ul>
				</div>
				<?php 
                wp_reset_postdata();
                break;
            case 'popular_posts':
                $postargs = array('posts_per_page' => $instance['amount'], 'order' => 'DESC', 'orderby' => 'comment_count');
                $postslist = get_posts($postargs);
                ?>
				<div class="recent-posts">
					<ul>
						<?php 
                foreach ($postslist as $post) {
                    setup_postdata($post);
                    ?>
 
							<li>
								<div class="post-wrapper">
									<div class="post-thumb">
										<a href="<?php 
                    the_permalink();
                    ?>
"><?php 
                    the_post_thumbnail(array(50, 50));
                    ?>
</a>
									</div>
									<div class="post-info">
										<h3 class="post-title"><a href="<?php 
                    the_permalink();
                    ?>
"><?php 
                    the_title();
                    ?>
</a></h3>
										<div class="post-date">
											<?php 
                    echo get_the_date();
                    ?>
										</div>
									</div>
								</div>
							</li>
						<?php 
                }
                ?>
					</ul>
				</div>
				<?php 
                wp_reset_postdata();
                break;
            case 'recent_comments':
                $commentargs = array('status' => 'approve', 'post_type' => 'post', 'number' => $instance['amount']);
                $comments = get_comments($commentargs);
                ?>
				<ul>
					<?php 
                foreach ($comments as $comment) {
                    ?>
					<li>
						<div class="post-wrapper">
							<div class="post-thumb">
								<?php 
                    echo get_avatar($comment->comment_author_email, 50, '', '');
                    ?>
							</div>
							<div class="post-info">
								<p><?php 
                    echo esc_html($comment->comment_author);
                    ?>
 <?php 
                    esc_html_e('says', 'mirano');
                    ?>
:</p>
								<a href="<?php 
                    echo get_comments_link($comment->comment_post_ID);
                    ?>
" title="<?php 
                    echo esc_attr($comment->comment_author . ' on ' . get_the_title($comment->comment_post_ID));
                    ?>
"><?php 
                    echo Mirano_Theme::roadlimitStringByWord($comment->comment_content, 30, '...');
                    ?>
</a>
							</div>
						</div>
					</li>
					<?php 
                }
                ?>
				</ul>	
				<?php 
                break;
        }
        echo wp_kses($args['after_widget'], array('aside' => array('id' => array(), 'class' => array()), 'h3' => array('class' => array()), 'span' => array('class' => array())));
    }