コード例 #1
0
    function widget($args, $instance)
    {
        global $wpdb, $current_site, $post, $wiki_tree;
        extract($args);
        $instance = apply_filters('eab-widgets-popular-instance_read', $instance, $this);
        $options = wp_parse_args((array) $instance, $this->_defaults);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Most Popular', $this->translation_domain) : $instance['title'], $instance, $this->id_base);
        $_events = Eab_CollectionFactory::get_popular_events(array('posts_per_page' => $options['limit']));
        if (is_array($_events) && count($_events) > 0) {
            ?>
		<?php 
            echo $before_widget;
            ?>
		<?php 
            echo $before_title . $title . $after_title;
            ?>
	            <div id="event-popular">
			<ul>
			    <?php 
            foreach ($_events as $_event) {
                $thumbnail = $excerpt = false;
                if ($options['thumbnail']) {
                    $raw = wp_get_attachment_image_src(get_post_thumbnail_id($_event->get_id()));
                    $thumbnail = $raw ? @$raw[0] : false;
                }
                $excerpt = false;
                if ($options['excerpt']) {
                    $words = (int) $options['excerpt_words_limit'] ? (int) $options['excerpt_words_limit'] : false;
                    $excerpt = eab_call_template('util_words_limit', $_event->get_excerpt_or_fallback(), $words);
                }
                ?>
				<li>
					<a href="<?php 
                print get_permalink($_event->get_id());
                ?>
" class="<?php 
                print $_event->get_id() == $post->ID ? 'current' : '';
                ?>
" >
						<?php 
                if ($options['thumbnail'] && $thumbnail) {
                    ?>
							<img src="<?php 
                    echo $thumbnail;
                    ?>
" /><br />
						<?php 
                }
                ?>
						<?php 
                print $_event->get_title();
                ?>
					</a>
					<?php 
                if ($options['excerpt'] && $excerpt) {
                    ?>
						<p><?php 
                    echo $excerpt;
                    ?>
</p>
					<?php 
                }
                ?>
					<?php 
                do_action('eab-widgets-popular-after_event', $options, $_event, $this);
                ?>
				</li>
			    <?php 
            }
            ?>
			</ul>
	            </div>
	        <br />
	        <?php 
            echo $after_widget;
            ?>
		<?php 
        } else {
            echo $before_widget . $before_title . $title . $after_title . '<p class="eab-widget-no_events">' . __('No popular events.', Eab_EventsHub::TEXT_DOMAIN) . '</p>' . $after_widget;
        }
    }