load-more.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * VamTam load more for Cube Portfolio
  4. *
  5. * @author Nikolay Yordanov <me@nyordanov.com>
  6. * @package vamtam/consulting
  7. */
  8. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  9. class VamtamLoadMore {
  10. private static $instance;
  11. public static function get_instance() {
  12. if ( ! isset( self::$instance ) ) {
  13. self::$instance = new self();
  14. }
  15. return self::$instance;
  16. }
  17. public function __construct() {
  18. add_action( 'wp_ajax_vamtam-load-more', array( $this, 'get_items' ) );
  19. add_action( 'wp_ajax_nopriv_vamtam-load-more', array( $this, 'get_items' ) );
  20. }
  21. public function get_items() {
  22. $query_args = array_intersect_key(
  23. $_POST['query'],
  24. array_flip( array(
  25. 'author',
  26. 'category__in',
  27. 'fields',
  28. 'fl_builder_loop',
  29. 'ignore_sticky_posts',
  30. 'order',
  31. 'orderby',
  32. 'paged',
  33. 'post__in',
  34. 'post__not_in',
  35. 'post_type',
  36. 'posts_per_page',
  37. 'tax_query',
  38. ) ) // allowed query args
  39. );
  40. if ( ! isset( $query_args['post_type'] ) ) {
  41. $query_args['post_type'] = 'post';
  42. }
  43. $other_vars = array();
  44. $GLOBALS['vamtam_inside_cube'] = true;
  45. ob_start();
  46. $query = new WP_Query( $query_args );
  47. while ( $query->have_posts() ) {
  48. $query->the_post();
  49. if ( 'jetpack-portfolio' === $query_args['post_type'] ) {
  50. // sanitize
  51. $_POST['other_vars']['pagination'] = vamtam_sanitize_bool( $_POST['other_vars']['pagination'] );
  52. $_POST['other_vars']['show_title'] = vamtam_sanitize_bool( $_POST['other_vars']['show_title'] );
  53. $_POST['other_vars']['description'] = vamtam_sanitize_bool( $_POST['other_vars']['description'] );
  54. // filter
  55. $settings = $other_vars = (object) array_intersect_key(
  56. $_POST['other_vars'],
  57. array_flip( array( 'pagination', 'link_opens', 'show_title', 'description', 'columns', 'layout', 'hover_animation' ) ) // allowed keys
  58. );
  59. include locate_template( 'templates/portfolio/loop/item.php' );
  60. } elseif ( 'post' === $query_args['post_type'] ) {
  61. global $vamtam_loop_vars;
  62. $vamtam_loop_vars = $other_vars = array_intersect_key(
  63. $_POST['other_vars'],
  64. array_flip( array( 'show_content', 'show_title', 'show_media', 'news', 'columns', 'layout' ) ) // allowed keys
  65. );
  66. extract( $other_vars );
  67. $post_class = array(
  68. 'page-content post-header',
  69. 'list-item',
  70. 'cbp-item',
  71. );
  72. if ( ! in_array( $layout, array( 'mosaic', 'grid' ), true ) ) {
  73. $post_class[] = "grid-1-$columns";
  74. } else {
  75. $post_class[] = "vamtam-percentage-1-$columns";
  76. }
  77. ?>
  78. <div <?php post_class( implode( ' ', $post_class ) ) ?> >
  79. <div>
  80. <?php get_template_part( 'templates/post' ); ?>
  81. </div>
  82. </div>
  83. <?php
  84. }
  85. }// End while().
  86. header( 'Content-Type: application/json' );
  87. echo json_encode( array(
  88. 'content' => ob_get_clean(),
  89. 'button' => VamtamTemplates::pagination( 'load-more', false, $other_vars, $query ),
  90. ) );
  91. exit;
  92. }
  93. }