Пример #1
0
    /**
     * Display widget
     */
    function widget($args, $instance)
    {
        extract($args, EXTR_SKIP);
        global $post, $javo_tso;
        $title = apply_filters('widget_title', $instance['title']);
        $limit = $instance['limit'];
        $length = (int) $instance['length'];
        $thumb = $instance['thumb'];
        $cat = $instance['cat'];
        $post_type = $instance['post_type'];
        echo $before_widget;
        if (!empty($title)) {
            echo $before_title . $title . $after_title;
        }
        if (false === ($javo_recent_photos = get_transient('javo_recent_photos_' . $widget_id))) {
            $args = array('numberposts' => $limit, 'cat' => $cat, 'post_type' => $post_type, 'post_status' => 'publish');
            $javo_recent_photos = query_posts($args);
            set_transient('javo_recent_photos_' . $widget_id, $javo_recent_photos, 60 * 60 * 12);
        }
        ?>

		<div class="widget_posts_wrap">
			<?php 
        switch ($post_type) {
            case "lister":
                //************* listers **************//
                ?>
<ul class='latest-posts listers'><?php 
                $javo_recent_photos = query_posts(array('post_status' => 'publish', 'post_type' => $post_type, 'posts_per_page' => $limit, 'cat' => $cat));
                foreach ($javo_recent_photos as $post) {
                    setup_postdata($post);
                    $author = get_userdata($post->post_author);
                    $avatar = !empty($author) ? get_user_meta($author->ID, "avatar", true) : null;
                    $avatar_meta = wp_get_attachment_image_src($avatar, 'javo-tiny');
                    $avatar_src = $avatar_meta[0];
                    ?>
					<li class="col-xs-4 col-sm-4 col-md-4">
						<?php 
                    if ($thumb == true) {
                        ?>
						<span class='thumb'><a href="<?php 
                        echo get_the_permalink($post->ID);
                        ?>
">
							<?php 
                        //echo get_the_post_thumbnail($post->ID, "javo-tiny"); //get_avatar( get_the_author_meta('ID'), 32 );
                        ?>
							<div class="img-wrap-shadow"><img src='<?php 
                        echo $avatar_src;
                        ?>
'></div>
						</a></span>
						<?php 
                    }
                    ?>
					</li>
				<?php 
                }
                wp_reset_postdata();
                ?>
</ul><?php 
                break;
            case "item":
                //************* item **************//
                ?>
<ul class='latest-posts items list-unstyled'><?php 
                $javo_recent_photos = query_posts(array('post_status' => 'publish', 'post_type' => $post_type, 'posts_per_page' => $limit, 'cat' => $cat));
                foreach ($javo_recent_photos as $post) {
                    setup_postdata($post);
                    ?>
					<li class="col-xs-4 col-sm-4 col-md-4">
						<?php 
                    if ($thumb == true) {
                        ?>
						<span class='thumb'>
							<a href="<?php 
                        the_permalink();
                        ?>
">
							<div class="img-wrap-shadow">
								<?php 
                        if (has_post_thumbnail()) {
                            the_post_thumbnail('javo-tiny');
                        } else {
                            printf('<img src="%s" class="wp-post-image" style="width:80px; height:80px;">', $javo_tso->get('no_image', JAVO_IMG_DIR . '/no-image.png'));
                        }
                        ?>
								</div>
							</a>
						</span>
						<?php 
                    }
                    ?>
					</li>
				<?php 
                }
                wp_reset_postdata();
                ?>
</ul><?php 
                break;
            case "post":
            default:
                //************* Post **************//
                ?>
				<!--<ul class='latest-posts posts'><?php 
                if (!empty($javo_recent_posts)) {
                    foreach ($javo_recent_posts as $post) {
                        setup_postdata($post);
                        ?>
						<li class="col-md-12">
							<?php 
                        if ($thumb == true) {
                            ?>
							<span class='thumb'><a href="<?php 
                            the_permalink();
                            ?>
"><?php 
                            echo get_the_post_thumbnail($post->ID, "javo-tiny");
                            //get_avatar( get_the_author_meta('ID'), 32 );
                            ?>
</a></span>
							<?php 
                        }
                        ?>
							<p><?php 
                        the_title();
                        ?>
 <br/><?php 
                        echo word_trim(get_the_excerpt(), $length, '...');
                        ?>
<a href="<?php 
                        the_permalink();
                        ?>
"><?php 
                        _e("read more", 'javo_fr');
                        ?>
</a></p>
						</li>
					<?php 
                    }
                    wp_reset_postdata();
                }
                ?>
</ul>-->
			<ul class='latest-posts items list-unstyled'>
				<?php 
                $javo_recent_photos_args = array('post_status' => 'publish', 'post_type' => $post_type, 'posts_per_page' => $limit, 'cat' => $cat);
                $javo_recent_photos = new WP_Query($javo_recent_photos_args);
                if ($javo_recent_photos->have_posts()) {
                    while ($javo_recent_photos->have_posts()) {
                        $javo_recent_photos->the_post();
                        $javo_this_permalink = '';
                        switch ($post_type) {
                            case 'jv_events':
                                $javo_this_permalink = javo_url(get_post_meta(get_the_ID(), 'parent_post_id', true));
                                break;
                            case 'review':
                                $javo_this_permalink = javo_url(get_post_meta(get_the_ID(), 'parent_post_id', true));
                                break;
                            default:
                                $javo_this_permalink = get_permalink();
                        }
                        ?>
						<li class="col-xs-4 col-sm-4 col-md-4">
						<?php 
                        if ($thumb == true) {
                            ?>
							<span class='thumb'>
								<a href="<?php 
                            echo $javo_this_permalink;
                            if ($post_type == 'jv_events') {
                                echo '#item-events';
                            } else {
                                if ($post_type == 'review') {
                                    echo '#item-reviews';
                                }
                            }
                            ?>
">
									<div class="img-wrap-shadow">
										<?php 
                            if (has_post_thumbnail()) {
                                the_post_thumbnail('javo-tiny');
                            } else {
                                printf('<img src="%s" class="wp-post-image" style="width:80px; height:80px;">', $javo_tso->get('no_image', JAVO_IMG_DIR . '/no-image.png'));
                            }
                            ?>
									</div>
								</a>
							</span>
							<?php 
                        }
                        ?>
						</li>
						<?php 
                    }
                    // End While
                }
                // End if
                ?>
			</ul>
			<?php 
        }
        ?>
		</div>
		<?php 
        wp_reset_query();
        echo $after_widget;
    }
Пример #2
0
    function widget($args, $instance)
    {
        global $javo_tso;
        extract($args, EXTR_SKIP);
        $javo_query = new javo_ARRAY($instance);
        $javo_this_post_type = $javo_query->get('post_type', 'post');
        $javo_this_post_excerpt_limit = (int) $javo_query->get('excerpt_length', 20);
        $javo_this_widget_title = apply_filters('widget_title', $javo_query->get('title', null));
        $javo_this_posts_args = array('post_type' => $javo_this_post_type, 'posts_per_page' => (int) $javo_query->get('post_count', 3), 'post_status' => 'publish');
        $javo_this_posts = new WP_Query($javo_this_posts_args);
        ob_start();
        echo $before_widget;
        echo $before_title . $javo_this_widget_title . $after_title;
        ?>
		<div class="widget_posts_wrap">
			<?php 
        if ($javo_this_posts->have_posts()) {
            while ($javo_this_posts->have_posts()) {
                $javo_this_posts->the_post();
                switch ($javo_this_post_type) {
                    case 'jv_events':
                        $javo_this_permalink = javo_url(get_post_meta(get_the_ID(), 'parent_post_id', true)) . '#item-events';
                        break;
                    case 'review':
                        $javo_this_permalink = javo_url(get_post_meta(get_the_ID(), 'parent_post_id', true)) . '#item-reviews';
                        break;
                    default:
                        $javo_this_permalink = get_permalink();
                }
                ?>
					<div class="latest-posts posts row">
						<div class="col-md-12">
							<span class='thumb'>
								<a href="<?php 
                echo $javo_this_permalink;
                ?>
">
									<?php 
                if (has_post_thumbnail()) {
                    the_post_thumbnail('javo-tiny');
                } else {
                    printf('<img src="%s" class="wp-post-image" style="width:50px; height:50px;">', $javo_tso->get('no_image', JAVO_IMG_DIR . '/no-image.png'));
                }
                ?>
								</a>
							</span>
							<?php 
                printf('<h3><a href="%s">%s</a></h3><a href="%s"><span>%s</span></a>', $javo_this_permalink, javo_str_cut(get_the_title(), 20), $javo_this_permalink, javo_str_cut(strip_tags(get_the_excerpt()), $javo_this_post_excerpt_limit));
                ?>
						</div><!-- /.col-md-12 -->
					</div><!-- /.row -->
					<?php 
            }
        } else {
            _e('Not Found Posts.', 'javo_fr');
        }
        ?>
		</div><!-- /.widget_posts_wrap -->
		<?php 
        wp_reset_query();
        echo $after_widget;
        ob_end_flush();
    }