Guest User

Untitled

a guest
May 26th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. add_action( 'widgets_init','WL_recent_works1');
  2. function WL_recent_works1() { return register_widget( 'WL_footer_recent_works1' ); }
  3.  
  4. class WL_footer_recent_works1 extends WP_Widget {
  5. function __construct() {
  6. parent::__construct(
  7. 'WL_footer_recent_works1', // Base ID
  8. __('Enigma Recent Posts1', 'weblizar'), // Name
  9. array( 'description' => __( 'The Recent post display on your sites', 'weblizar' ), ) // Args
  10. );
  11. }
  12. public function widget( $args, $instance ) {
  13. $title = apply_filters( 'widget_title', $instance['title'] );
  14. $number_of_posts = apply_filters( 'widget_title', $instance['number_of_posts'] );
  15. $blog_cat = apply_filters( 'widget_title', $instance['blog_cat'] );
  16. if($number_of_posts=='') { $number_of_posts = 5; }
  17.  
  18. echo $args['before_widget'];
  19. if ( ! empty( $title ) )
  20. echo $args['before_title'] . $title . $args['after_title']; ?>
  21. <?php $loop = new WP_Query(array( 'post_type' => 'post', 'showposts' => $number_of_posts , 'category_name' => $blog_cat ));
  22. if( $loop->have_posts() ) : ?>
  23. <?php while ( $loop->have_posts() ) : $loop->the_post();?>
  24. <div class="media enigma_recent_widget_post">
  25. <?php if(has_post_thumbnail()):
  26. $default = array('class' =>"enigma_recent_widget_post_img"); ?>
  27. <a class="enigma_recent_widget_post_move" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
  28. <?php the_post_thumbnail('recent_blog_img',$default); ?>
  29. </a>
  30. <?php endif;?>
  31. <div class="media-body">
  32. <h3><a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a></h3>
  33. <span class="enigma_recent_widget_post_date"><?php echo get_the_date( 'F j, Y' ); ?></span>
  34. </div>
  35. </div>
  36. <?php endwhile; ?>
  37. <?php endif; ?>
  38. <?php
  39. echo $args['after_widget'];
  40. }
  41. public function form( $instance ) {
  42. if ( isset( $instance[ 'title' ] ) && isset( $instance[ 'number_of_posts' ] )) {
  43. $title = $instance[ 'title' ];
  44. $number_of_posts = $instance[ 'number_of_posts' ];
  45. $blog_cat = $instance['blog_cat'];
  46. }
  47. else {
  48. $title = __( 'Recent Post', 'weblizar' );
  49. $number_of_posts = 4;
  50. }
  51. ?>
  52. <p>
  53. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:','weblizar' ); ?></label>
  54. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
  55. </p>
  56. <p>
  57. <label for="<?php echo $this->get_field_id( 'number_of_posts' ); ?>"><?php _e( 'Number of pages to show:','weblizar' ); ?></label>
  58. <input size="3" maxlength="2"id="<?php echo $this->get_field_id( 'number_of_posts' ); ?>" name="<?php echo $this->get_field_name( 'number_of_posts' ); ?>" type="text" value="<?php echo esc_attr( $number_of_posts ); ?>" />
  59.  
  60. <label for="<?php echo $this->get_field_id( 'blog_cat' ); ?>"><?php _e( 'Enter category','weblizar' ); ?></label>
  61. <input id="<?php echo $this->get_field_id( 'blog_cat' ); ?>" name="<?php echo $this->get_field_name( 'blog_cat' ); ?>" type="text" value="<?php echo esc_attr( $blog_cat ); ?>" />
  62. </p>
  63. <?php
  64. }
  65. public function update( $new_instance, $old_instance ) {
  66. $instance = array();
  67. $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
  68. $instance['number_of_posts'] = ( ! empty( $new_instance['number_of_posts'] ) ) ? strip_tags( $new_instance['number_of_posts'] ) : '';
  69. $instance['blog_cat'] = ( ! empty( $new_instance['blog_cat'] ) ) ? strip_tags( $new_instance['blog_cat'] ) : '';
  70. return $instance;
  71. }
  72. }
Add Comment
Please, Sign In to add comment