示例#1
0
function wallow_the_thumb()
{
    if (wallow_get_opt('wallow_pthumb')) {
        echo wallow_get_the_thumb(array('class' => 'alignleft', 'linked' => true));
    }
}
示例#2
0
    function widget($args, $instance)
    {
        $cache = wp_cache_get('wlw-widget_recent_posts', 'widget');
        if (!is_array($cache)) {
            $cache = array();
        }
        if (isset($cache[$args['widget_id']])) {
            echo $cache[$args['widget_id']];
            return;
        }
        ob_start();
        extract($args);
        $use_thumbs = !isset($instance['thumb']) || ($thumb = (int) $instance['thumb']) ? 1 : 0;
        $category = isset($instance['category']) ? absint($instance['category']) : '';
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts in %s', 'wallow') : $instance['title'], $instance, $this->id_base);
        $title = sprintf($title, '<a href="' . esc_url(get_category_link($category)) . '">' . get_cat_name($category) . '</a>');
        if (!($number = absint($instance['number']))) {
            $number = 10;
        }
        $r = new WP_Query(array('cat' => $category, 'posts_per_page' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
        if ($r->have_posts()) {
            ?>
		<?php 
            echo $before_widget;
            ?>
		<?php 
            if ($title) {
                echo $before_title . $title . $after_title;
            }
            ?>
		<ul<?php 
            if ($use_thumbs) {
                echo ' class="with-thumbs"';
            }
            ?>
>
		<?php 
            while ($r->have_posts()) {
                $r->the_post();
                ?>
			<li>
				<a href="<?php 
                the_permalink();
                ?>
" title="<?php 
                echo esc_attr(get_the_title() ? get_the_title() : get_the_date());
                ?>
"><?php 
                if ($use_thumbs) {
                    echo wallow_get_the_thumb(array('id' => get_the_ID(), 'width' => 50, 'height' => 50));
                }
                if (get_the_title()) {
                    the_title();
                } else {
                    echo get_the_date();
                }
                ?>
</a>
			</li>
		<?php 
            }
            ?>
		</ul>
		<?php 
            echo $after_widget;
            // Reset the global $the_post as this query will have stomped on it
            wp_reset_postdata();
        }
        $cache[$args['widget_id']] = ob_get_flush();
        wp_cache_set('wlw-widget_recent_posts', $cache, 'widget');
    }