Created
November 5, 2016 17:58
-
-
Save rozziecole/88719e3cbcf0f758ecd110c1bece9377 to your computer and use it in GitHub Desktop.
Code for MH_slider widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***** Slider Widget (Homepage) *****/ | |
class mh_slider_hp_widget extends WP_Widget { | |
function mh_slider_hp_widget () { | |
$widget_ops = array('classname' => 'mh_slider_hp', 'description' => __('Slider widget for use on homepage templates', 'mh')); | |
$this->WP_Widget('mh_slider_hp', __('MH Slider Widget (Homepage)', 'mh'), $widget_ops); | |
} | |
function widget($args, $instance) { | |
extract($args); | |
$postcount = empty($instance['postcount']) ? '5' : $instance['postcount']; | |
$cats = empty($instance['cats']) ? '' : $instance['cats']; | |
$tags = empty($instance['tags']) ? '' : $instance['tags']; | |
$offset = empty($instance['offset']) ? '' : $instance['offset']; | |
$order = isset($instance['order']) ? $instance['order'] : 'date'; | |
echo $before_widget; ?> | |
<section id="slider" class="flexslider"> | |
<ul class="slides"> | |
<?php | |
$args = array('posts_per_page' => $postcount, 'cat' => $cats, 'tag' => $tags, 'offset' => $offset, 'orderby' => $order); | |
$slider = new WP_query($args); | |
while ($slider->have_posts()) : $slider->the_post(); ?> | |
<li> | |
<article class="slide-wrap"> | |
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> | |
<?php if (has_post_thumbnail()) { the_post_thumbnail('slider'); } else { echo '<img src="' . get_template_directory_uri() . '/images/noimage_940x400.png' . '" alt="No Picture" />'; } ?> | |
</a> | |
<div class="slide-caption"> | |
<div class="slide-data"> | |
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><h2 class="slide-title"><?php the_title(); ?></h2></a> | |
<div class="slide-excerpt"><?php the_excerpt(); ?></div> | |
</div> | |
</div> | |
</article> | |
</li> | |
<?php endwhile; wp_reset_postdata(); ?> | |
</ul> | |
</section> | |
<?php | |
echo $after_widget; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment