Advertisement
Guest User

Dark - wp widget

a guest
Dec 5th, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  
  5. * Warrior Posts Box Type Four
  6.  
  7. *
  8.  
  9. * This file contains Posts in Category widget
  10.  
  11. * @copyright Copyright (c) 2012, Warrior
  12.  
  13. */
  14.  
  15. // Widgets
  16.  
  17. add_action( 'widgets_init', 'warrior_posts_box_four_widget' );
  18.  
  19.  
  20.  
  21. // Register our widget
  22.  
  23. function warrior_posts_box_four_widget() {
  24.  
  25. register_widget( 'Warrior_Posts_Box_Four' );
  26.  
  27. }
  28.  
  29.  
  30.  
  31. // Warrior Widget
  32.  
  33. class Warrior_Posts_Box_Four extends WP_Widget {
  34.  
  35.  
  36.  
  37. // Setting up the widget
  38.  
  39. function Warrior_Posts_Box_Four() {
  40.  
  41. $widget_ops = array( 'classname' => 'warrior_posts_box_four', 'description' => __('Posts box type four.', 'warrior') );
  42.  
  43. $control_ops = array( 'id_base' => 'warrior_posts_box_four' );
  44.  
  45.  
  46.  
  47. $this->WP_Widget( 'warrior_posts_box_four', __('Home: Posts Box Type Four', 'warrior'), $widget_ops, $control_ops );
  48.  
  49. }
  50.  
  51.  
  52.  
  53. function widget( $args, $instance ) {
  54.  
  55. global $shortname;
  56.  
  57.  
  58.  
  59. extract( $args );
  60.  
  61.  
  62.  
  63. if ( empty( $instance['warrior_posts_list'] ) || ! $warrior_posts_list = absint( $instance['warrior_posts_list'] ) ) $warrior_posts_list = 5;
  64.  
  65. elseif ( $instance['warrior_posts_list'] > 10 ) $warrior_posts_list = 10;
  66.  
  67. $warrior_posts_cat_left = $instance['warrior_posts_cat_l'];
  68.  
  69. $warrior_posts_cat_right= $instance['warrior_posts_cat_r'];
  70.  
  71.  
  72.  
  73. echo $before_widget;
  74.  
  75. ?>
  76.  
  77. <div class="hentry left">
  78.  
  79. <?php
  80.  
  81. // Start fetching the post from database
  82.  
  83. $warrior_posts_list_left = new WP_Query("showposts=$warrior_posts_list&cat=$warrior_posts_cat_left");
  84.  
  85. $i = 1; while($warrior_posts_list_left->have_posts()) : $warrior_posts_list_left->the_post();
  86.  
  87. if ( $i == 1 ) {
  88.  
  89. ?>
  90.  
  91. <div class="thumb">
  92.  
  93. <?php warrior_thumbnail( 'both', '300', '170', 'cat-large-thumb', get_the_title()); ?>
  94.  
  95. <span class="category"><?php the_category(', '); ?></span>
  96.  
  97. </div>
  98.  
  99. <div class="inner">
  100.  
  101. <h3 class="title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo warrior_post_title('35'); ?></a></h3>
  102.  
  103. <p><?php echo warrior_excerpt(100);?></p>
  104.  
  105. <?php if ( $warrior_posts_list_left->post_count > 1) echo '<ul>'; ?>
  106.  
  107. <?php } else { ?>
  108.  
  109. <li>
  110.  
  111. <span class="icon-file"></span> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo warrior_post_title('35'); ?></a>
  112.  
  113. </li>
  114.  
  115. <?php } ?>
  116.  
  117. <?php $i = $i + 1; endwhile; ?>
  118.  
  119. <?php if ( $warrior_posts_list_left->post_count > 1) echo '</ul>'; ?>
  120.  
  121. </div>
  122.  
  123. </div>
  124.  
  125. <?php wp_reset_query(); ?>
  126.  
  127.  
  128.  
  129. <div class="hentry right">
  130.  
  131. <?php
  132.  
  133. // Start fetching the post from database
  134.  
  135. $warrior_posts_list_right = new WP_Query("showposts=$warrior_posts_list&cat=$warrior_posts_cat_right");
  136.  
  137. $i = 1; while($warrior_posts_list_right->have_posts()) : $warrior_posts_list_right->the_post();
  138.  
  139. if ( $i == 1 ) {
  140.  
  141. ?>
  142.  
  143. <div class="thumb">
  144.  
  145. <?php warrior_thumbnail( 'both', '300', '170', 'cat-large-thumb', get_the_title()); ?>
  146.  
  147. <span class="category"><?php the_category(', '); ?></span>
  148.  
  149. </div>
  150.  
  151. <div class="inner">
  152.  
  153. <h3 class="title" style="color:red"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo warrior_post_title('35'); ?></a></h3>
  154.  
  155. <p><?php echo warrior_excerpt(100);?></p>
  156.  
  157. <?php if ( $warrior_posts_list_right->post_count > 1) echo '<ul>'; ?>
  158.  
  159. <?php } else { ?>
  160.  
  161. <li>
  162.  
  163. <span class="icon-file"></span> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo warrior_post_title('35'); ?></a>
  164.  
  165. </li>
  166.  
  167. <?php } ?>
  168.  
  169. <?php $i = $i + 1; endwhile; ?>
  170.  
  171. <?php if ( $warrior_posts_list_right->post_count > 1) echo '</ul>'; ?>
  172.  
  173. </div>
  174.  
  175. </div>
  176.  
  177. <?php wp_reset_query(); ?>
  178.  
  179. <?php
  180.  
  181. echo $after_widget;
  182.  
  183. }
  184.  
  185.  
  186.  
  187. function update( $new_instance, $old_instance ) {
  188.  
  189. $instance = $old_instance;
  190.  
  191.  
  192.  
  193. $instance['warrior_posts_list'] = strip_tags( $new_instance['warrior_posts_list'] );
  194.  
  195. $instance['warrior_posts_cat_l'] = strip_tags( $new_instance['warrior_posts_cat_l'] );
  196.  
  197. $instance['warrior_posts_cat_r'] = strip_tags( $new_instance['warrior_posts_cat_r'] );
  198.  
  199.  
  200.  
  201. return $instance;
  202.  
  203. }
  204.  
  205.  
  206.  
  207. function form( $instance ) {
  208.  
  209. $instance = wp_parse_args( (array) $instance, array('warrior_posts_list'=>'5') );
  210.  
  211.  
  212.  
  213. $categories = get_categories();
  214.  
  215. ?>
  216.  
  217.  
  218.  
  219. <p>
  220.  
  221. <label for="<?php echo $this->get_field_id( 'warrior_posts_cat_l' ); ?>"><?php _e('Select Posts Category - Left Block:', 'warrior'); ?></label>
  222.  
  223. <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'); ?>">
  224.  
  225. <option value=""><?php _e('Select Category', 'warrior'); ?></option>
  226.  
  227. <?php
  228.  
  229. foreach ( $categories as $category ) {
  230.  
  231. echo '<option value="' . intval($category->cat_ID) . '"'
  232.  
  233. . ( $category->cat_ID == $instance['warrior_posts_cat_l'] ? ' selected="selected"' : '' )
  234.  
  235. . '>' . $category->cat_name . ' (' . sprintf( __('%s posts', 'warrior'), $category->category_count ) . ')' . "</option>\n";
  236.  
  237. }
  238.  
  239. ?>
  240.  
  241. </select>
  242.  
  243. </p>
  244.  
  245.  
  246.  
  247. <p>
  248.  
  249. <label for="<?php echo $this->get_field_id( 'warrior_posts_cat_r' ); ?>"><?php _e('Select Posts Category - Right Block:', 'warrior'); ?></label>
  250.  
  251. <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'); ?>">
  252.  
  253. <option value=""><?php _e('Select Category', 'warrior'); ?></option>
  254.  
  255. <?php
  256.  
  257. foreach ( $categories as $category ) {
  258.  
  259. echo '<option value="' . intval($category->cat_ID) . '"'
  260.  
  261. . ( $category->cat_ID == $instance['warrior_posts_cat_r'] ? ' selected="selected"' : '' )
  262.  
  263. . '>' . $category->cat_name . ' (' . sprintf( __('%s posts', 'warrior'), $category->category_count ) . ')' . "</option>\n";
  264.  
  265. }
  266.  
  267. ?>
  268.  
  269. </select>
  270.  
  271. </p>
  272.  
  273.  
  274.  
  275. <p>
  276.  
  277. <label for="<?php echo $this->get_field_id( 'warrior_posts_list' ); ?>"><?php _e('Number of Posts to be Displayed:', 'warrior'); ?></label>
  278.  
  279. <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']; ?>" />
  280.  
  281. </p>
  282.  
  283. <?php
  284.  
  285. }
  286.  
  287. }
  288.  
  289. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement