I made the following widget code to show Featured Category with Video embed code.
The following widget works with Videozoom theme from WPZoom
Open wpzoom-widgets.php in the functions folder of Videozom. Add the following code at the bottom of the wpzoom-widgets.php
/*---------------------------------------------*/ /* WPZOOM: Featured Category widget with Video */ /*---------------------------------------------*/ add_action('widgets_init', create_function('', 'return register_widget("wpzoom_widget_fea_cat_video_posts");')); class wpzoom_widget_fea_cat_video_posts extends WP_Widget { /* Widget setup. */ function wpzoom_widget_fea_cat_video_posts() { /* Widget settings. */ $widget_ops = array( 'classname' => 'wpzoom', 'description' => __('Featured Category Widget', 'wpzoom') ); /* Widget control settings. */ $control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => 'wpzoom-widget-cat' ); /* Create the widget. */ $this->WP_Widget( 'wpzoom-widget-cat', __('WPZOOM: Featured Category', 'wpzoom'), $widget_ops, $control_ops ); } /* How to display the widget on the screen. */ function widget( $args, $instance ) { extract( $args ); /* Our variables from the widget settings. */ $title1 = apply_filters('widget_title', $instance['title1'] ); $posts1 = $instance['posts1']; $category1 = get_category($instance['category1']); if ($category1) { $categoryLink1 = get_category_link($category1); } $videowidth = $instance['videowidth']; $videoheight = $instance['videoheight']; echo $before_widget; echo "$before_title"."$title1"."$after_title"; ?> <ul class="posts"> <?php $args = array('showposts' => $posts1, 'orderby' => 'date', 'order' => 'DESC', 'cat' => $instance['category1']); query_posts($args); global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } } while (have_posts()) : the_post(); ?> <li> <?php global $post; unset($videocode); $videocode = get_post_meta($post->ID, 'wpzoom_post_embed_code', true); $video_hd = get_post_meta($post->ID, 'wpzoom_post_embed_hd', true); if (strlen($videocode) > 1) { // Do we embed a video from a website? $videocode = preg_replace("/(width\s*=\s*[\"\'])[0-9]+([\"\'])/i", "$1 $videowidth $2", $videocode); $videocode = preg_replace("/(height\s*=\s*[\"\'])[0-9]+([\"\'])/i", "$1 $videoheight $2", $videocode); $videocode = str_replace("<embed","<param name='wmode' value='transparent'></param><embed",$videocode); $videocode = str_replace("<embed","<embed wmode='transparent' ",$videocode); ?> <div class="cover"><?php echo "$videocode"; ?></div> <?php } elseif (strlen($videocode) < 1) { unset($videocode); $videocode = get_post_meta($post->ID, 'wpzoom_post_embed_self', true); if (strlen($videocode) > 1) { // Let's embed a self-hosted video! $skin = strtolower(get_post_meta($post->ID, 'wpzoom_post_embed_skin', true)); ?> <div class="cover"> <div id='video_<?php echo the_ID() ; ?>'>Video</div> <script type='text/javascript'> jwplayer('video_<?php echo the_ID(); ?>').setup({ 'file': '<?php echo "$videocode"; ?>', 'skin': '<?php bloginfo('template_directory'); ?>/js/skins/<?php echo "$skin/$skin.zip"; ?>', 'image' : '<?php echo "$img"; ?>', 'width': '<?php echo "$videowidth"; ?>', 'height': '<?php echo "$videoheight"; ?>', <?php if (strlen($video_hd) > 1) { ?>'plugins': { 'hd-1': { 'file': '<?php echo "$video_hd"; ?>' } }, <?php } ?> 'modes': [ {type: 'flash', src: '<?php bloginfo('template_directory'); ?>/js/player.swf'}, {type: 'html5'} ] }); </script> </div> <?php } } if (!$videocode) { // No video? Show a picture then unset($img); if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) { $thumbURL = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '' ); $img = $thumbURL[0]; } else { unset($img); if ($wpzoom_cf_use == 'Yes') { $img = get_post_meta($post->ID, $wpzoom_cf_photo, true); } else { if (!$img) { $img = catch_that_image($post->ID); } } } if ($img) : $img = wpzoom_wpmu($img); ?> <div class="cover"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $img ?>&h=45&w=60&zc=1" alt="<?php the_title(); ?>" /></a></div> <?php endif; } ?> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> <p class="postmetadata"> <a href="<?php the_permalink() ?>#commentspost" title="Jump to the comments"><?php comments_number('0 comments','1 comment','% comments'); ?></a></p> <div class="cleaner"> </div> </li> <?php endwhile; wp_reset_query(); ?> </ul><!-- end .posts --> <?php echo $after_widget; wp_reset_query(); } /* Update the widget settings.*/ function update( $new_instance, $old_instance ) { $instance = $old_instance; /* Strip tags for title and name to remove HTML (important for text inputs). */ $instance['title1'] = strip_tags( $new_instance['title1'] ); $instance['category1'] = $new_instance['category1']; $instance['posts1'] = $new_instance['posts1']; $instance['videowidth'] = $new_instance['videowidth']; $instance['videoheight'] = $new_instance['videoheight']; return $instance; } /** Displays the widget settings controls on the widget panel. * Make use of the get_field_id() and get_field_name() function when creating your form elements. This handles the confusing stuff. */ function form( $instance ) { /* Set up some default widget settings. */ $defaults = array( 'title1' => __('Featured Posts', 'wpzoom'), 'category1' => '0', 'posts1' => '3' ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <p> <label for="<?php echo $this->get_field_id( 'title1' ); ?>"><?php _e('Widget Title:', 'wpzoom'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'title1' ); ?>" name="<?php echo $this->get_field_name( 'title1' ); ?>" value="<?php echo $instance['title1']; ?>" style="width:90%;" /> </p> <p> <label for="<?php echo $this->get_field_id('category1'); ?>"><?php _e('Category:', 'wpzoom'); ?></label> <select id="<?php echo $this->get_field_id('category1'); ?>" name="<?php echo $this->get_field_name('category1'); ?>" style="width:90%;"> <option value="0">Choose category:</option> <?php $cats = get_categories('hide_empty=0'); foreach ($cats as $cat) { $option = '<option value="'.$cat->term_id; if ($cat->term_id == $instance['category1']) { $option .='" selected="selected';} $option .= '">'; $option .= $cat->cat_name; $option .= ' ('.$cat->category_count.')'; $option .= '</option>'; echo $option; } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('posts1'); ?>"><?php _e('Number of posts to show:', 'wpzoom'); ?></label> <select id="<?php echo $this->get_field_id('posts1'); ?>" name="<?php echo $this->get_field_name('posts1'); ?>" style="width:90%;"> <?php $m = 0; while ($m < 11) { $m++; $option = '<option value="'.$m; if ($m == $instance['posts1']) { $option .='" selected="selected';} $option .= '">'; $option .= $m; $option .= '</option>'; echo $option; } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id( 'videowidth' ); ?>"><?php _e('Video Width:', 'wpzoom'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'videowidth' ); ?>" name="<?php echo $this->get_field_name( 'videowidth' ); ?>" value="<?php echo $instance['videowidth']; ?>" style="width:90%;" /> </p> <p> <label for="<?php echo $this->get_field_id( 'videoheight' ); ?>"><?php _e('Video Height:', 'wpzoom'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'videoheight' ); ?>" name="<?php echo $this->get_field_name( 'videoheight' ); ?>" value="<?php echo $instance['videoheight']; ?>" style="width:90%;" /> </p> <?php } }
Leave a Reply