Advertisement
delvinkrasniqi

Untitled

Mar 13th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. function blog_scripts2() {
  2. // Register the script
  3. wp_register_script( 'custom-script2', get_stylesheet_directory_uri(). '/js/customjs2.js', array('jquery'), false, true );
  4.  
  5. // Localize the script with new data
  6. $script_data_array = array(
  7. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  8. 'security' => wp_create_nonce( 'load_more_posts2' ),
  9. );
  10. wp_localize_script( 'custom-script2', 'blog2', $script_data_array );
  11.  
  12. // Enqueued script with localized data.
  13. wp_enqueue_script( 'custom-script2' );
  14. }
  15. add_action( 'wp_enqueue_scripts', 'blog_scripts2' );
  16.  
  17.  
  18.  
  19. function load_posts_by_ajax_callback2() {
  20. check_ajax_referer('load_more_posts2', 'security');
  21. $paged = $_POST['page'];
  22. $args = array(
  23. 'post_type' => 'galleryimages',
  24. 'post_status' => 'publish',
  25. 'posts_per_page' => '3',
  26. 'order'=>'ASC',
  27. 'paged' => $paged,
  28. );
  29. $my_posts = new WP_Query( $args );
  30. ?>
  31.  
  32. <?php if ( $my_posts->have_posts() ) : ?>
  33. <?php while ( $my_posts->have_posts() ) : $my_posts->the_post(); ?>
  34.  
  35.  
  36. <div class="col-lg-4 col-md-6 col-sm-12 col-12 p-0" data-aos="zoom-in" data-aos-duration="1500">
  37. <a href="<?php the_post_thumbnail_url();?>" class="lightbox">
  38. <?php the_post_thumbnail();?>
  39. </a>
  40. </div>
  41. <script src="https://cdnjs.cloudflare.com/ajax/libs/baguettebox.js/1.8.1/baguetteBox.min.js"></script>
  42. <script>
  43. baguetteBox.run('.tz-gallery');
  44. </script>
  45.  
  46.  
  47. <?php endwhile; ?>
  48. <?php
  49. endif;
  50. ?>
  51. <?php
  52.  
  53. wp_die();
  54.  
  55. }
  56. add_action('wp_ajax_load_posts_by_ajax2', 'load_posts_by_ajax_callback2');
  57. add_action('wp_ajax_nopriv_load_posts_by_ajax2', 'load_posts_by_ajax_callback2');
  58.  
  59. ////
  60. js/custom-js.js
  61. var page = 2;
  62. jQuery(function($) {
  63. jQuery('body').on('click', '.loadmore2', function() {
  64. var data2 = {
  65. 'action': 'load_posts_by_ajax2',
  66. 'page': page,
  67. 'security': blog2.security
  68. };
  69.  
  70. $.post(blog2.ajaxurl, data2, function(response2) {
  71. if(response2 != '') {
  72. jQuery('.roww').append(response2);
  73. page++;
  74. } else {
  75. jQuery('.loadmore2').hide();
  76. }
  77.  
  78. });
  79. });
  80. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement