Code is the problem or is a Google Chrome issue?
Here is the code:
/*-----------------------------------------------------------------------------------*/
/* Create the widget
/*-----------------------------------------------------------------------------------*/
add_action('widgets_init', 'bd_post_types_init');
function bd_post_types_init(){
register_widget('bd_post_types_widget');
}
/*-----------------------------------------------------------------------------------*/
/* Widget class
/*-----------------------------------------------------------------------------------*/
class bd_post_types_widget extends WP_Widget {
/*-----------------------------------------------------------------------------------*/
/* Widget Setup
/*-----------------------------------------------------------------------------------*/
function bd_post_types_widget(){
// Widget settings
$ops = array('classname' => 'post-types-widget', 'description' => __('Display any post type: recent or popular, as text link or thumbnail', THEME_NAME) );
// Create the widget
$this->WP_Widget('post-types-widget', 'Post Types (All in one)', $ops);
}
/*-----------------------------------------------------------------------------------*/
/* Display Widget
/*-----------------------------------------------------------------------------------*/
function widget($args, $instance){
extract($args);
$title = apply_filters('widget_title', $instance['title']);
$count = $instance['count'];
echo $before_widget;
if (!empty($title)) echo $before_title . $title . $after_title;
bd_post_types_widget($count, $instance['post-type'], $instance['type'], $instance['display'], $instance['category']);
echo $after_widget;
}
/*-----------------------------------------------------------------------------------*/
/* Update Widget
/*-----------------------------------------------------------------------------------*/
function update($new_instance, $old_instance){
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['count'] = $new_instance['count'];
$instance['type'] = $new_instance['type'];
$instance['post-type'] = $new_instance['post-type'];
$instance['display'] = $new_instance['display'];
$instance['category'] = $new_instance['category'];
return $instance;
}
/*-----------------------------------------------------------------------------------*/
/* Displays the widget settings controls on the widget panel
/*-----------------------------------------------------------------------------------*/
function form($instance){
global $BD_theme;
// Set up some default widget settings
$defaults = array('title' => 'Recent Post', 'post-type' => '', 'count' =>'5', 'type' => 'thumbnail', 'display' => 'recent', 'category' => 'all');
$instance = wp_parse_args((array) $instance, $defaults);
$post_types = '';
if(isset($BD_theme->options['post-types']) && is_array($BD_theme->options['post-types']))
$post_types = $BD_theme->options['post-types'];
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', THEME_NAME); ?>:</label>
<input class="widefat" type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>">
</p>
<p>
<label for="<?php echo $this->get_field_id('post-type'); ?>"><?php _e('Post Type', THEME_NAME ); ?>:</label><br>
<select class="bd-cat-select" name="<?php echo $this->get_field_name('post-type'); ?>" id="<?php echo $this->get_field_id('post-type'); ?>">
<option value="post" <?php if($instance['post-type']=='post') echo 'selected="selected"'; ?>>Post</option>
<?php foreach($post_types as $k => $v):
$name = $k;
if(isset($v['name']))
$name = $v['name'].'s';
if(isset($v['menu-name']))
$name = $v['menu-name'];
?>
<option value="<?php echo $k; ?>" <?php if($instance['post-type']==$k) echo 'selected="selected"'; ?>><?php echo $name; ?></option>
<?php endforeach ; ?>
</select>
</p>
<p id="bd-blog-categories">
<label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Post Category (if post is selected)', THEME_NAME ); ?>:</label><br>
<select name="<?php echo $this->get_field_name('category'); ?>" id="<?php echo $this->get_field_id('category'); ?>">
<?php
$bd_categories = get_categories();
$bd_categories_tab = array();
foreach($bd_categories as $category){
$bd_categories_tab['all'] = 'All';
$bd_categories_tab[$category->cat_ID] = $category->name;
}
foreach($bd_categories_tab as $k => $v):?>
<option value="<?php echo $k; ?>" <?php if($instance['category']==$k) echo 'selected="selected"'; ?>><?php echo $v; ?></option>
<?php endforeach; ?>
</select>
<?php //debug($bd_categories_tab); ?>
</p>
<p>
<label for="<?php echo $this->get_field_id('display'); ?>"><?php _e('Display', THEME_NAME ); ?>:</label><br>
<select name="<?php echo $this->get_field_name('display'); ?>" id="<?php echo $this->get_field_id('display'); ?>">
<option <?php if($instance['display']=='recent') echo 'selected="selected"'; ?>><?php _e('recent', THEME_NAME ); ?></option>
<option <?php if($instance['display']=='featured') echo 'selected="selected"'; ?>><?php _e('featured', THEME_NAME ); ?></option>
<option <?php if($instance['display']=='popular') echo 'selected="selected"'; ?>><?php _e('popular', THEME_NAME ); ?></option>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Number of post', THEME_NAME ); ?>:</label>
<input class="widefat" type="text" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" value="<?php echo $instance['count']; ?>">
</p>
<p>
<label for="<?php echo $this->get_field_id('type'); ?>"><?php _e('Type' ,THEME_NAME ); ?>:</label>
<select name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>">
<option <?php if($instance['type']=='thumbnail') echo 'selected="selected"'; ?>><?php _e('thumbnail', THEME_NAME ); ?></option>
<option <?php if($instance['type']=='text') echo 'selected="selected"'; ?>><?php _e('text', THEME_NAME ); ?></option>
<?php if($BD_theme->options['video'] != array()): ?>
<option <?php if($instance['type']=='video') echo 'selected="selected"'; ?> value="video"><?php _e('video (only for video post types)', THEME_NAME ); ?></option>
<?php endif; ?>
</select>
</p>
<?php
}
}
/*-----------------------------------------------------------------------------------*/
/* Function
/*-----------------------------------------------------------------------------------*/
function bd_post_types_widget($count=5, $post_type, $type, $display, $category){
global $wpdb, $BD_theme, $post, $bd_ID;
$do_not_duplicate = array();
if(is_single())
//echo $bd_ID;
$do_not_duplicate[] = $bd_ID;
$is_video = (in_array($post_type, $BD_theme->options['video'])) && ($post_type!='post');
//$do_not_duplicate[] = $post->ID;
if($type!='text'){
if($display=='recent'){
$args = array(
'post_type' => array($post_type) ,
'posts_per_page' => $count,
'meta_key' => '_thumbnail_id',
'post__not_in' => $do_not_duplicate
);
}elseif($display=='featured'){
$args = array(
'post_type' => array($post_type) ,
'orderby' => 'post_date',
'meta_key' => '_thumbnail_id',
'posts_per_page' => $count,
'post__not_in' => $do_not_duplicate,
'meta_query' => array(
array(
'key' => 'bd_featured',
'value' => 'on',
'compare' => '='
)
)
);
}elseif($display=='popular'){
$args = array(
'post_type' => array($post_type) ,
'orderby' => 'comment_count',
'meta_key' => '_thumbnail_id',
'order' => 'DESC',
'posts_per_page' => $count,
'post__not_in' => $do_not_duplicate,
);
}
}else{
if($display=='recent'){
$args = array(
'post_type' => array($post_type) ,
'posts_per_page' => $count,
'post__not_in' => $do_not_duplicate
);
}elseif($display=='featured'){
$args = array(
'post_type' => array($post_type) ,
'orderby' => 'post_date',
'posts_per_page' => $count,
'post__not_in' => $do_not_duplicate,
'meta_query' => array(
array(
'key' => 'bd_featured',
'value' => 'on',
'compare' => '='
)
)
);
}elseif($display=='popular'){
$args = array(
'post_type' => array($post_type) ,
'orderby' => 'comment_count',
'order' => 'DESC',
'posts_per_page' => $count,
'post__not_in' => $do_not_duplicate,
);
}
}
if($post_type == 'post' && $category!='all'){
$args['category__in'] = $category;
}
$loop = new WP_Query($args);
if ( $type=='text'){
echo "<ul class=\"square\">";
}elseif ( $type=='thumbnail' || $type=='video'){
echo '<div class="widget-thumbnails-list">';
}
while ($loop->have_posts()) : $loop->the_post();
?>
<?php if ( $type=='video'): ?>
<?php if($is_video): ?>
<article>
<div class="frame" style="margin-top:15px; margin-bottom:5px">
<?php echo get_post_meta($post->ID, '_format_video_embed', true); ?>
</div>
<strong class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php _e('Permanent Link to', THEME_NAME); ?> <?php the_title(); ?>"><?php the_title(); ?></a></strong>
<br>
<small class="smooth"><?php echo get_the_time('F d, 20y'); ?></small>
</article>
<?php else: ?>
<article>
<a href="<?php the_permalink(); ?>" class="widget-thumb-link">
<?php the_post_thumbnail('mini', array('class' => 'frame', 'title' => "")); ?>
</a>
<strong class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php _e('Permanent Link to', THEME_NAME); ?> <?php the_title(); ?>"><?php the_title(); ?></a></strong><br>
<small class="smooth"><?php echo get_the_time('F d, 20y'); ?></small><br>
<small class="smooth"><?php bd_comment_number(); ?></small>
<?php if( get_post_meta($post->ID, 'bd_rating', true)!=''): ?>
<br>
<span class="small-star-<?php echo str_replace('.5', '-5', get_post_meta($post->ID, 'bd_rating', true)); ?>"></span>
<?php endif; ?>
<div class="clear"></div>
</article>
<?php endif; ?>
<?php elseif ( ($type=='thumbnail') ): ?>
<?php if($is_video): ?>
<article>
<div class="video-thumbnail">
<a class="video-thumbnail-link" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('video-thumbnail-img', array('class' => '')); ?>
<span class="play-button-thumb"></span>
</a>
<strong class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php _e('Permanent Link to', THEME_NAME); ?> <?php the_title(); ?>"><?php the_title(); ?></a></strong>
<br>
<small class="smooth"><?php echo get_the_time('F d, 20y'); ?></small><br>
<small class="smooth"><?php bd_comment_number(); ?></small>
<div class="clear"></div>
</div>
</article>
<?php else: ?>
<article>
<a href="<?php the_permalink(); ?>" class="widget-thumb-link">
<?php the_post_thumbnail('mini', array('class' => 'frame effect', 'title' => "")); ?>
</a>
<strong class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php _e('Permanent Link to', THEME_NAME); ?> <?php the_title(); ?>"><?php the_title(); ?></a></strong>
<br>
<small class="smooth"><?php echo get_the_time('F d, 20y'); ?></small><br>
<small class="smooth"><?php bd_comment_number(); ?></small>
<?php if( get_post_meta($post->ID, 'bd_rating', true)!=''): ?>
<br>
<span class="small-star-<?php echo str_replace('.5', '-5', get_post_meta($post->ID, 'bd_rating', true)); ?>"></span>
<?php endif; ?>
<div class="clear"></div>
</article>
<?php endif; ?>
<div class="clear"></div>
<?php else: // if text ?>
<li>
<a href="<?php the_permalink(); ?>" class="hover">
<?php echo get_the_title(); ?>
</a>
</li>
<?php endif; ?>
<?php
endwhile;
if ( $type=='text'){
echo "</ul>";
}else{
echo '</div>';
}
?><div class="clear"></div><?php
}

