Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Warrior Posts Box Type Four
- *
- * This file contains Posts in Category widget
- * @copyright Copyright (c) 2012, Warrior
- */
- // Widgets
- add_action( 'widgets_init', 'warrior_posts_box_four_widget' );
- // Register our widget
- function warrior_posts_box_four_widget() {
- register_widget( 'Warrior_Posts_Box_Four' );
- }
- // Warrior Widget
- class Warrior_Posts_Box_Four extends WP_Widget {
- // Setting up the widget
- function Warrior_Posts_Box_Four() {
- $widget_ops = array( 'classname' => 'warrior_posts_box_four', 'description' => __('Posts box type four.', 'warrior') );
- $control_ops = array( 'id_base' => 'warrior_posts_box_four' );
- $this->WP_Widget( 'warrior_posts_box_four', __('Home: Posts Box Type Four', 'warrior'), $widget_ops, $control_ops );
- }
- function widget( $args, $instance ) {
- global $shortname;
- extract( $args );
- if ( empty( $instance['warrior_posts_list'] ) || ! $warrior_posts_list = absint( $instance['warrior_posts_list'] ) ) $warrior_posts_list = 5;
- elseif ( $instance['warrior_posts_list'] > 10 ) $warrior_posts_list = 10;
- $warrior_posts_cat_left = $instance['warrior_posts_cat_l'];
- $warrior_posts_cat_right= $instance['warrior_posts_cat_r'];
- echo $before_widget;
- ?>
- <div class="hentry left">
- <?php
- // Start fetching the post from database
- $warrior_posts_list_left = new WP_Query("showposts=$warrior_posts_list&cat=$warrior_posts_cat_left");
- $i = 1; while($warrior_posts_list_left->have_posts()) : $warrior_posts_list_left->the_post();
- if ( $i == 1 ) {
- ?>
- <div class="thumb">
- <?php warrior_thumbnail( 'both', '300', '170', 'cat-large-thumb', get_the_title()); ?>
- <span class="category"><?php the_category(', '); ?></span>
- </div>
- <div class="inner">
- <h3 class="title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo warrior_post_title('35'); ?></a></h3>
- <p><?php echo warrior_excerpt(100);?></p>
- <?php if ( $warrior_posts_list_left->post_count > 1) echo '<ul>'; ?>
- <?php } else { ?>
- <li>
- <span class="icon-file"></span> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo warrior_post_title('35'); ?></a>
- </li>
- <?php } ?>
- <?php $i = $i + 1; endwhile; ?>
- <?php if ( $warrior_posts_list_left->post_count > 1) echo '</ul>'; ?>
- </div>
- </div>
- <?php wp_reset_query(); ?>
- <div class="hentry right">
- <?php
- // Start fetching the post from database
- $warrior_posts_list_right = new WP_Query("showposts=$warrior_posts_list&cat=$warrior_posts_cat_right");
- $i = 1; while($warrior_posts_list_right->have_posts()) : $warrior_posts_list_right->the_post();
- if ( $i == 1 ) {
- ?>
- <div class="thumb">
- <?php warrior_thumbnail( 'both', '300', '170', 'cat-large-thumb', get_the_title()); ?>
- <span class="category"><?php the_category(', '); ?></span>
- </div>
- <div class="inner">
- <h3 class="title" style="color:red"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo warrior_post_title('35'); ?></a></h3>
- <p><?php echo warrior_excerpt(100);?></p>
- <?php if ( $warrior_posts_list_right->post_count > 1) echo '<ul>'; ?>
- <?php } else { ?>
- <li>
- <span class="icon-file"></span> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo warrior_post_title('35'); ?></a>
- </li>
- <?php } ?>
- <?php $i = $i + 1; endwhile; ?>
- <?php if ( $warrior_posts_list_right->post_count > 1) echo '</ul>'; ?>
- </div>
- </div>
- <?php wp_reset_query(); ?>
- <?php
- echo $after_widget;
- }
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $instance['warrior_posts_list'] = strip_tags( $new_instance['warrior_posts_list'] );
- $instance['warrior_posts_cat_l'] = strip_tags( $new_instance['warrior_posts_cat_l'] );
- $instance['warrior_posts_cat_r'] = strip_tags( $new_instance['warrior_posts_cat_r'] );
- return $instance;
- }
- function form( $instance ) {
- $instance = wp_parse_args( (array) $instance, array('warrior_posts_list'=>'5') );
- $categories = get_categories();
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'warrior_posts_cat_l' ); ?>"><?php _e('Select Posts Category - Left Block:', 'warrior'); ?></label>
- <select class="widefat" id="<?php echo $this->get_field_id('warrior_posts_cat_l'); ?>" name="<?php echo $this->get_field_name('warrior_posts_cat_l'); ?>">
- <option value=""><?php _e('Select Category', 'warrior'); ?></option>
- <?php
- foreach ( $categories as $category ) {
- echo '<option value="' . intval($category->cat_ID) . '"'
- . ( $category->cat_ID == $instance['warrior_posts_cat_l'] ? ' selected="selected"' : '' )
- . '>' . $category->cat_name . ' (' . sprintf( __('%s posts', 'warrior'), $category->category_count ) . ')' . "</option>\n";
- }
- ?>
- </select>
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'warrior_posts_cat_r' ); ?>"><?php _e('Select Posts Category - Right Block:', 'warrior'); ?></label>
- <select class="widefat" id="<?php echo $this->get_field_id('warrior_posts_cat_r'); ?>" name="<?php echo $this->get_field_name('warrior_posts_cat_r'); ?>">
- <option value=""><?php _e('Select Category', 'warrior'); ?></option>
- <?php
- foreach ( $categories as $category ) {
- echo '<option value="' . intval($category->cat_ID) . '"'
- . ( $category->cat_ID == $instance['warrior_posts_cat_r'] ? ' selected="selected"' : '' )
- . '>' . $category->cat_name . ' (' . sprintf( __('%s posts', 'warrior'), $category->category_count ) . ')' . "</option>\n";
- }
- ?>
- </select>
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'warrior_posts_list' ); ?>"><?php _e('Number of Posts to be Displayed:', 'warrior'); ?></label>
- <input id="<?php echo $this->get_field_id( 'warrior_posts_list' ); ?>" class="widefat" name="<?php echo $this->get_field_name( 'warrior_posts_list' ); ?>" value="<?php echo $instance['warrior_posts_list']; ?>" />
- </p>
- <?php
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement