Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. /**
  2. * Extend Recent Posts Widget
  3. *
  4. * Adds different formatting to the default WordPress Recent Posts Widget
  5. */
  6.  
  7. Class My_Recent_Posts_Widget extends WP_Widget_Recent_Posts {
  8.  
  9. function widget($args, $instance) {
  10.  
  11. extract( $args );
  12.  
  13. $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
  14.  
  15. if( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
  16. $number = 10;
  17.  
  18. $r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );
  19. if( $r->have_posts() ) :
  20.  
  21. echo $before_widget;
  22. if( $title ) echo $before_title . $title . $after_title; ?>
  23. <ul>
  24. <?php while( $r->have_posts() ) : $r->the_post(); ?>
  25. <li><h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
  26. <p><?php the_excerpt(); ?></p>
  27. <p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="read-more">READ MORE</a></li>
  28. <?php endwhile; ?>
  29. </ul>
  30.  
  31. <?php
  32. echo $after_widget;
  33.  
  34. wp_reset_postdata();
  35.  
  36. endif;
  37. }
  38. }
  39. function my_recent_widget_registration() {
  40. unregister_widget('WP_Widget_Recent_Posts');
  41. register_widget('My_Recent_Posts_Widget');
  42. }
  43. add_action('widgets_init', 'my_recent_widget_registration');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement