Advertisement
Guest User

Untitled

a guest
Jan 7th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.79 KB | None | 0 0
  1. <?php
  2. add_action('widgets_init', 'Reedwan_Magazine_load_widgets');
  3.  
  4. function Reedwan_Magazine_load_widgets()
  5. {
  6. register_widget('Reedwan_Magazine_Widget');
  7. }
  8.  
  9. class Reedwan_Magazine_Widget extends WP_Widget {
  10.  
  11. function Reedwan_Magazine_Widget()
  12. {
  13. $widget_ops = array('classname' => 'reedwan_magazine', 'description' => '1 Column magazine recent posts widget for magazine widget.');
  14.  
  15. $control_ops = array('id_base' => 'reedwan_magazine-widget');
  16.  
  17. $this->WP_Widget('reedwan_magazine-widget', 'Echeion : 1 Column Magazine', $widget_ops, $control_ops);
  18. }
  19.  
  20. function widget($args, $instance)
  21. {
  22. extract($args);
  23.  
  24. $title = $instance['title'];
  25. $post_type = 'all';
  26. $categories = $instance['categories'];
  27. $posts = $instance['posts'];
  28. $show_image = isset($instance['show_image']) ? 'true' : 'false';
  29. echo $before_widget;
  30. ?>
  31.  
  32. <?php
  33. $post_types = get_post_types();
  34. unset($post_types['page'], $post_types['portfolio'], $post_types['gallery'], $post_types['reviews'], $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item']);
  35.  
  36. if($post_type == 'all') {
  37. $post_type_array = $post_types;
  38. } else {
  39. $post_type_array = $post_type;
  40. }
  41. ?>
  42.  
  43. <div class="widget-magazine">
  44. <?php
  45. if($title) {
  46. echo $before_title.$title.$after_title;
  47. }
  48. ?>
  49. <?php
  50. $recent_posts = new WP_Query(array(
  51. 'showposts' => $posts,
  52. 'post_type' => $post_type_array,
  53. 'cat' => $categories,
  54. ));
  55. ?>
  56. <?php
  57. $big_count = round($posts / 5);
  58. if(!$big_count) { $big_count = 1; }
  59. ?>
  60. <?php
  61. $counter = 1;
  62. while($recent_posts->have_posts()): $recent_posts->the_post();
  63. if(has_post_format('video'))
  64. {
  65. $format_icon = 'class="video-format-icon"';
  66. $format_icon_small = ' (Video)';
  67. }
  68. else if (has_post_format('audio'))
  69. {
  70. $format_icon = 'class="audio-format-icon"';
  71. $format_icon_small = ' (Audio)';
  72. }
  73. else if (has_post_format('gallery'))
  74. {
  75. $format_icon = 'class="gallery-format-icon"';
  76. $format_icon_small = ' (Gallery)';
  77. }
  78. else {
  79. $format_icon = 'class="standard-format-icon"';
  80. $format_icon_small = '';
  81. }
  82. ?>
  83. <?php if($counter <= $big_count): ?>
  84. <?php if($counter == $big_count) { $last = 'block-big-last'; } else { $last = ''; }?>
  85.  
  86. <div class="block-big <?php echo $last; ?>">
  87. <?php if(has_post_thumbnail()): ?>
  88. <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'big-post-thumb'); ?>
  89. <div class="magz-image"><a <?php echo $format_icon; ?> href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img class="fadeover" src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='300' height='150' /></a>
  90. </div>
  91. <?php else: ?>
  92. <div class="magz-image"><a <?php echo $format_icon; ?> href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img class="fadeover" src="<?php echo get_template_directory_uri(); ?>/images/thumbnail.png" alt="<?php the_title(); ?>" width='300' height='150' /></a>
  93. </div>
  94. <?php endif; ?>
  95. <div class="big-desc">
  96. <div class="big-title"><h3><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h3></div>
  97. <div class="magz-meta">Pubblicato <?php the_time('j F, Y'); ?> | <iframe src="http://www.facebook.com/plugins/comments.php?href=<?php the_permalink(); ?>&permalink=1" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:130px; height:12px;" allowTransparency="true"></iframe></div>
  98. <p><?php echo string_limit_words(get_the_excerpt(), 25); ?><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>' class="readmore"> [...]</a></p>
  99.  
  100. </div>
  101. </div>
  102.  
  103. <?php else: ?>
  104. <?php if($show_image == 'true'): ?>
  105. <div class="block-small<?php if($counter%2 != 0) { echo " right"; } else { echo " left"; }?>">
  106. <?php if(has_post_thumbnail()): ?>
  107. <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'small-post-thumb'); ?>
  108. <div class="magz-image"><a <?php echo $format_icon; ?> href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img class="fadeover" src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='75' height='60' /></a></div>
  109. <?php else: ?>
  110. <div class="magz-image"><a <?php echo $format_icon; ?> href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img class="fadeover" src="<?php echo get_template_directory_uri(); ?>/images/thumbnail.png" alt="<?php the_title(); ?>" width='75' height='60' /></a></div>
  111. <?php endif; ?>
  112. <div class="description">
  113. <h3><a class="des-title" href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title_limit( 52, '...'); ?></a></h3>
  114. <div class="magz-meta"><?php the_time('j F, Y'); ?></div>
  115. <p><?php echo string_limit_words(get_the_excerpt(), 18); ?><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>' class="readmore"> [...]</a></p>
  116. </div>
  117. </div>
  118. <?php endif; ?>
  119. <?php if($show_image == 'false'): ?>
  120. <div class="block-small-noimage<?php if($counter%2 != 0) { echo " right"; } else { echo " left"; }?>">
  121. <h3><a class="des-title" href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?><?php echo $format_icon_small; ?></a></h3>
  122. <p><?php echo string_limit_words(get_the_excerpt(), 35); ?><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>' class="readmore"> [...]</a></p>
  123. </div>
  124. <?php endif; ?>
  125. <?php endif; ?>
  126. <?php $counter++; endwhile; ?>
  127.  
  128. </div>
  129. <?php
  130. echo $after_widget;
  131. }
  132.  
  133. function update($new_instance, $old_instance)
  134. {
  135. $instance = $old_instance;
  136.  
  137. $instance['title'] = $new_instance['title'];
  138. $instance['post_type'] = 'all';
  139. $instance['categories'] = $new_instance['categories'];
  140. $instance['posts'] = $new_instance['posts'];
  141. $instance['show_image'] = $new_instance['show_image'];
  142. return $instance;
  143. }
  144.  
  145. function form($instance)
  146. {
  147. $defaults = array('title' => 'Recent Posts', 'post_type' => 'all', 'categories' => 'all', 'posts' => 5, 'show_image'=>null );
  148. $instance = wp_parse_args((array) $instance, $defaults); ?>
  149. <p>
  150. <label for="<?php echo $this->get_field_id('title'); ?>">Title</label>
  151. <input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" />
  152. </p>
  153.  
  154. <p>
  155. <label for="<?php echo $this->get_field_id('categories'); ?>">Filter by Category</label>
  156. <select id="<?php echo $this->get_field_id('categories'); ?>" name="<?php echo $this->get_field_name('categories'); ?>" class="widefat categories" style="width:100%;">
  157. <option value='all' <?php if ('all' == $instance['categories']) echo 'selected="selected"'; ?>>all categories</option>
  158. <?php $categories = get_categories('hide_empty=0&depth=1&type=post'); ?>
  159. <?php foreach($categories as $category) { ?>
  160. <option value='<?php echo $category->term_id; ?>' <?php if ($category->term_id == $instance['categories']) echo 'selected="selected"'; ?>><?php echo $category->cat_name; ?></option>
  161. <?php } ?>
  162. </select>
  163. </p>
  164.  
  165. <p>
  166. <label for="<?php echo $this->get_field_id('posts'); ?>">Number of posts</label>
  167. <input class="widefat" style="width: 30px;" id="<?php echo $this->get_field_id('posts'); ?>" name="<?php echo $this->get_field_name('posts'); ?>" value="<?php echo $instance['posts']; ?>" />
  168.  
  169. </p>
  170. <p>
  171. <input class="checkbox" type="checkbox" <?php checked($instance['show_image'], 'on'); ?> id="<?php echo $this->get_field_id('show_image'); ?>" name="<?php echo $this->get_field_name('show_image'); ?>" />
  172. <label for="<?php echo $this->get_field_id('show_image'); ?>">Show thumbnail image</label>
  173. </p>
  174.  
  175. <?php }
  176. }
  177. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement