Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. if( !function_exists( 'shortcode_bethlehem_recent_posts_widget' ) ) {
  2. function shortcode_bethlehem_recent_posts_widget( $atts = array(), $content = null ) {
  3.  
  4. $default_atts = array(
  5. 'title' => '',
  6. 'pre_title' => '',
  7. 'limit' => '',
  8. 'type' => '',
  9. 'show_date' => '',
  10. 'el_class' => '',
  11. );
  12.  
  13. extract( array_merge( $default_atts, $atts ) );
  14.  
  15. $widget = 'Bethlehem_Widget_Recent_Posts';
  16.  
  17. $instance = array(
  18. 'title' => $title,
  19. 'type' => $type,
  20. 'number' => $limit,
  21. 'show_date' => $show_date,
  22. );
  23.  
  24. $before_widget = '<div class="widget vc_widget_recent_posts ' . esc_attr( $type ) .' '. esc_attr( $el_class ) . '">';
  25. $after_widget = '</div>';
  26. if( !empty( $pre_title ) ) {
  27. $before_title = '<h3 class="pre-title">'.$pre_title.'</h3><h3 class="widget-title">';
  28. $after_title = '</h3>';
  29. } else {
  30. $before_title = '<h3 class="widget-title">';
  31. $after_title = '</h3>';
  32. }
  33.  
  34. $args = array(
  35. 'before_widget' => $before_widget,
  36. 'after_widget' => $after_widget,
  37. 'before_title' => $before_title,
  38. 'after_title' => $after_title
  39. );
  40.  
  41. $output = '';
  42.  
  43. add_action( 'pre_get_posts', 'custom_blog_widget_category' );
  44. ob_start();
  45. the_widget( $widget, $instance, $args );
  46. $output .= ob_get_clean();
  47. remove_action( 'pre_get_posts', 'custom_blog_widget_category' );
  48.  
  49. return apply_filters( 'shortcode_beth_recent_posts_widget' , $output );
  50. }
  51. }
  52.  
  53. function custom_blog_widget_category( $query ) {
  54. $query->set( 'cat', '7'); // Add your category id here
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement