Advertisement
Guest User

Untitled

a guest
May 25th, 2023
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. function wp_display_post( $atts, $content = '' ) {
  2.  
  3. global $post;
  4.  
  5. // Shortcode Parameter
  6. $atts = shortcode_atts(array(
  7. 'limit' => 5,
  8. ), $atts, 'wp_display_post');
  9.  
  10. // WP Query Parameter
  11. $args = array (
  12. 'post_type' => 'post',
  13. 'post_status' => array( 'publish' ),
  14. 'posts_per_page' => $atts['limit'],
  15. 'ignore_sticky_posts' => true,
  16. );
  17.  
  18. ob_start();
  19.  
  20. $query = new WP_Query( $args );
  21.  
  22. // If post is there
  23. if( $query->have_posts() ) {
  24. while ($query->have_posts()) : $query->the_post();
  25. ?>
  26. <div class="wp-post-main">
  27. <div class="wp-post-title"><h4><?php the_title(); ?></h4></div>
  28.  
  29. <div class="wp-post-cnt-wrp">
  30. <?php
  31. if ( FLBuilderModel::is_builder_enabled( $post->ID ) ) {
  32. // Enqueue styles and scripts for this post.
  33. FLBuilder::enqueue_layout_styles_scripts_by_id( $post->ID );
  34.  
  35. // Render the builder content.
  36. FLBuilder::render_content_by_id( $post->ID );
  37. } else {
  38. the_content();
  39. }
  40. ?>
  41. </div>
  42. </div>
  43.  
  44. <?php
  45. endwhile;
  46. }
  47.  
  48. wp_reset_postdata(); // Reset WP Query
  49.  
  50. $content .= ob_get_clean();
  51. return $content;
  52. }
  53. add_shortcode( 'wp_display_post', 'wp_display_post' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement