Ejemplo n.º 1
0
    function widget($args, $instance)
    {
        $defaults = array('title' => '', 'category' => 0, 'tags' => '', 'postcount' => 5, 'offset' => 0, 'sticky' => 1);
        $instance = wp_parse_args($instance, $defaults);
        $query_args = array();
        if (0 !== $instance['category']) {
            $query_args['cat'] = $instance['category'];
        }
        if (!empty($instance['tags'])) {
            $tag_slugs = explode(',', $instance['tags']);
            $tag_slugs = array_map('trim', $tag_slugs);
            $query_args['tag_slug__in'] = $tag_slugs;
        }
        if (!empty($instance['postcount'])) {
            $query_args['posts_per_page'] = $instance['postcount'];
        }
        if (0 !== $instance['offset']) {
            $query_args['offset'] = $instance['offset'];
        }
        if (1 === $instance['sticky']) {
            $query_args['ignore_sticky_posts'] = true;
        }
        $widget_loop = new WP_Query($query_args);
        echo $args['before_widget'];
        if (!empty($instance['title'])) {
            echo $args['before_title'];
            if ($instance['category'] != 0) {
                echo '<a href="' . esc_url(get_category_link($instance['category'])) . '" class="mh-widget-title-link">';
            }
            echo esc_html(apply_filters('widget_title', $instance['title']));
            if ($instance['category'] != 0) {
                echo '</a>';
            }
            echo $args['after_title'];
        }
        ?>
			<ul class="mh-custom-posts-widget clearfix"><?php 
        while ($widget_loop->have_posts()) {
            $widget_loop->the_post();
            ?>
					<li class="mh-custom-posts-item mh-custom-posts-small clearfix">
						<div class="mh-custom-posts-thumb">
							<a href="<?php 
            the_permalink();
            ?>
" title="<?php 
            the_title_attribute();
            ?>
"><?php 
            if (has_post_thumbnail()) {
                the_post_thumbnail('mh-magazine-lite-small');
            } else {
                echo '<img class="mh-image-placeholder" src="' . get_template_directory_uri() . '/images/placeholder-small.png' . '" alt="No Picture" />';
            }
            ?>
							</a>
						</div>
						<header class="mh-custom-posts-header">
							<p class="mh-custom-posts-small-title">
								<a href="<?php 
            the_permalink();
            ?>
" title="<?php 
            the_title_attribute();
            ?>
">
									<?php 
            the_title();
            ?>
								</a>
							</p>
							<div class="mh-meta mh-custom-posts-meta">
								<?php 
            mh_magazine_lite_loop_meta();
            ?>
							</div>
						</header>
					</li><?php 
        }
        wp_reset_postdata();
        ?>
        	</ul><?php 
        echo $args['after_widget'];
    }
Ejemplo n.º 2
0
} else {
    echo '<img class="mh-image-placeholder" src="' . get_template_directory_uri() . '/images/placeholder-medium.png' . '" alt="No Picture" />';
}
?>
		</a>
	</div>
	<div class="mh-loop-content clearfix">
		<header class="mh-loop-header">
			<h3 class="entry-title mh-loop-title">
				<a href="<?php 
the_permalink();
?>
" rel="bookmark">
					<?php 
the_title();
?>
				</a>
			</h3>
			<div class="mh-meta mh-loop-meta">
				<?php 
mh_magazine_lite_loop_meta();
?>
			</div>
		</header>
		<div class="mh-loop-excerpt">
			<?php 
the_excerpt();
?>
		</div>
	</div>
</article>