Advertisement
delvinkrasniqi

Untitled

Feb 6th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1.  
  2.  
  3. function blog_scripts2() {
  4. // Register the script
  5. wp_register_script( 'custom-script2', get_stylesheet_directory_uri(). '/js/customjs2.js', array('jquery'), false, true );
  6.  
  7. // Localize the script with new data
  8. $script_data_array = array(
  9. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  10. 'security' => wp_create_nonce( 'load_more_posts' ),
  11. );
  12. wp_localize_script( 'custom-script2', 'blog2', $script_data_array );
  13.  
  14. // Enqueued script with localized data.
  15. wp_enqueue_script( 'custom-script2' );
  16. }
  17. add_action( 'wp_enqueue_scripts', 'blog_scripts2' );
  18.  
  19.  
  20.  
  21. function load_posts_by_ajax_callback2() {
  22. check_ajax_referer('load_more_posts', 'security');
  23. $paged = $_POST['page'];
  24. $args = array(
  25. 'post_type' => 'galleryimages',
  26. 'post_status' => 'publish',
  27. 'posts_per_page' => '6',
  28. 'order'=>'ASC',
  29. 'paged' => $paged,
  30. );
  31. $my_posts = new WP_Query( $args );
  32. ?>
  33.  
  34. <?php if ( $my_posts->have_posts() ) : ?>
  35. <?php while ( $my_posts->have_posts() ) : $my_posts->the_post(); ?>
  36.  
  37.  
  38. <div class="col-lg-4 col-md-6 col-sm-12 col-12 p-0">
  39. <a href="<?php the_post_thumbnail_url();?>" class="lightbox">
  40. <?php the_post_thumbnail();?>
  41. </a>
  42. </div>
  43. <script src="https://cdnjs.cloudflare.com/ajax/libs/baguettebox.js/1.8.1/baguetteBox.min.js"></script>
  44. <script>
  45. baguetteBox.run('.tz-gallery');
  46. </script>
  47.  
  48.  
  49. <?php endwhile; ?>
  50. <?php
  51. endif;
  52.  
  53. wp_die();
  54. }
  55. add_action('wp_ajax_load_posts_by_ajax2', 'load_posts_by_ajax_callback2');
  56. add_action('wp_ajax_nopriv_load_posts_by_ajax', 'load_posts_by_ajax_callback2');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement