示例#1
0
    function widget($args, $instance)
    {
        $cache = wp_cache_get('sw-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);
        $instance = wp_parse_args((array) $instance, $this->default_options);
        $category = absint($instance['category']);
        $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
        $title = sprintf($title, '<a href="' . get_category_link($category) . '">' . get_cat_name($category) . '</a>');
        if (!($number = (int) $instance['number'])) {
            $number = 5;
        } else {
            if ($number < 1) {
                $number = 1;
            } else {
                if ($number > 15) {
                    $number = 15;
                }
            }
        }
        $use_thumbs = (int) $instance['thumb'];
        $thumb_size = (int) $instance['thumb_size'];
        $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 shiword_get_the_thumb(array('id' => get_the_ID(), 'width' => $thumb_size, 'height' => $thumb_size));
                }
                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('sw-widget_recent_posts', $cache, 'widget');
    }
示例#2
0
 function shiword_get_recententries($number = 10)
 {
     $r = new WP_Query(array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
     if ($r->have_posts()) {
         while ($r->have_posts()) {
             $r->the_post();
             $post_title = get_the_title();
             //shrink the post title if > 35 chars
             $post_title_short = mb_strimwidth($post_title, 0, 35, '&hellip;');
             $post_auth = mb_strimwidth(get_the_author(), 0, 20, '&hellip;');
             echo '<li><a href="' . esc_url(get_permalink()) . '" title="' . the_title_attribute(array('echo' => 0)) . '">' . $post_title_short . '</a> ' . sprintf(__('by %s', 'shiword'), $post_auth) . '<div class="preview">';
             if (post_password_required()) {
                 echo '<img class="alignleft wp-post-image"  height="48" width="48" src="' . esc_url(get_template_directory_uri() . '/images/thumb.png') . '" alt="thumb" title="' . esc_attr($post_title_short) . '" />';
                 echo '[' . __('No preview: this is a protected post', 'shiword') . ']';
             } else {
                 echo shiword_get_the_thumb(array('id' => get_the_ID(), 'width' => 48, 'height' => 48, 'class' => 'alignleft'));
                 the_excerpt();
             }
             echo '</div></li>';
         }
     }
     wp_reset_postdata();
 }
示例#3
0
    function shiword_post_title($args = '')
    {
        global $post;
        $defaults = array('alternative' => '', 'featured' => 0, 'href' => get_permalink(), 'target' => '', 'title' => the_title_attribute(array('echo' => 0)), 'extra' => '');
        $args = wp_parse_args($args, $defaults);
        $post_title = $args['alternative'] ? $args['alternative'] : get_the_title();
        $link_target = $args['target'] ? ' target="' . $args['target'] . '"' : '';
        $has_format = shiword_is_post_format_available($post->ID);
        $has_featured_image = $args['featured'] && shiword_get_opt('shiword_supadupa_title') && has_post_thumbnail($post->ID) && ($image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(700, 700))) && $image[1] >= 700 && $image[2] >= 200;
        if (!$has_format || is_singular() || shiword_get_opt('shiword_pthumb') && !has_post_thumbnail($post->ID)) {
            $miniicon = '';
        } else {
            $miniicon = apply_filters('shiword_filter_mini_icon', shiword_get_the_thumb(array('width' => 32, 'height' => 32, 'class' => 'alignleft', 'linked' => 1, 'onlyformat' => 1)));
        }
        if ($post_title) {
            $post_title = '<h2 class="storytitle entry-title">' . $miniicon . $args['extra'] . '<a title="' . esc_attr($args['title']) . '" href="' . esc_url($args['href']) . '"' . esc_attr($link_target) . ' rel="bookmark">' . $post_title . '</a></h2>';
        }
        shiword_hook_post_title_before();
        if ($has_featured_image) {
            ?>
			<div class="storycontent sd-post-title">
				<img src="<?php 
            echo esc_url($image[0]);
            ?>
" width="<?php 
            echo esc_attr($image[1]);
            ?>
" height="<?php 
            echo esc_attr($image[2]);
            ?>
">
				<?php 
            echo $post_title;
            ?>
			</div>
			<?php 
        } else {
            echo $post_title;
        }
        shiword_hook_post_title_after();
    }
示例#4
0
    function the_slider()
    {
        global $post;
        if (shiword_is_printpreview()) {
            return;
        }
        // no slider in print preview
        $posts_list = get_option('shiword_slideshow');
        //get the selected posts list
        if (!isset($posts_list) || empty($posts_list)) {
            return;
        }
        // if no post is selected, exit
        $args = array('post__in' => $posts_list, 'post_type' => 'any', 'orderby' => 'post__in', 'post_status' => 'publish', 'no_found_rows' => true, 'posts_per_page' => -1, 'ignore_sticky_posts' => true);
        $r = new WP_Query($args);
        if ($r->have_posts()) {
            ?>
			<div id="sw_slider-wrap">
				<div id="sw_sticky_slider">
<?php 
            while ($r->have_posts()) {
                $r->the_post();
                $post_author = !shiword_get_opt('shiword_sticky_author') ? '' : '<span class="sw-slider-auth">' . sprintf(__('by %s', 'shiword'), get_the_author()) . '</span>';
                ?>
						<div class="sss_item">
							<div class="sss_inner_item">
								<a href="<?php 
                echo esc_url(get_permalink());
                ?>
" title="<?php 
                the_title_attribute();
                ?>
">
									<?php 
                echo shiword_get_the_thumb(array('width' => 120, 'height' => 120, 'class' => 'alignleft'));
                ?>
								</a>
								<div style="padding-left: 130px;">
									<h2 class="storytitle"><a href="<?php 
                echo get_permalink($post->ID);
                ?>
" title="<?php 
                the_title_attribute();
                ?>
"><?php 
                the_title();
                ?>
</a></h2> <?php 
                echo $post_author;
                ?>
									<div class="storycontent">
										<?php 
                the_excerpt();
                ?>
									</div>
								</div>
							</div>
						</div>
<?php 
            }
            ?>
				</div>
				<div class="sw_slider-fade"> </div>
				<?php 
            if ($r->post_count > 1) {
                ?>
					<div class="sw_slider-skip toright"> </div>
					<div class="sw_slider-skip toleft"> </div>
				<?php 
            }
            ?>
			</div>
<?php 
        }
        wp_reset_postdata();
    }