Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function blog_scripts2() {
- // Register the script
- wp_register_script( 'custom-script2', get_stylesheet_directory_uri(). '/js/customjs2.js', array('jquery'), false, true );
- // Localize the script with new data
- $script_data_array = array(
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
- 'security' => wp_create_nonce( 'load_more_posts2' ),
- );
- wp_localize_script( 'custom-script2', 'blog2', $script_data_array );
- // Enqueued script with localized data.
- wp_enqueue_script( 'custom-script2' );
- }
- add_action( 'wp_enqueue_scripts', 'blog_scripts2' );
- function load_posts_by_ajax_callback2() {
- check_ajax_referer('load_more_posts2', 'security');
- $paged = $_POST['page'];
- $args = array(
- 'post_type' => 'galleryimages',
- 'post_status' => 'publish',
- 'posts_per_page' => '3',
- 'order'=>'ASC',
- 'paged' => $paged,
- );
- $my_posts = new WP_Query( $args );
- ?>
- <?php if ( $my_posts->have_posts() ) : ?>
- <?php while ( $my_posts->have_posts() ) : $my_posts->the_post(); ?>
- <div class="col-lg-4 col-md-6 col-sm-12 col-12 p-0" data-aos="zoom-in" data-aos-duration="1500">
- <a href="<?php the_post_thumbnail_url();?>" class="lightbox">
- <?php the_post_thumbnail();?>
- </a>
- </div>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/baguettebox.js/1.8.1/baguetteBox.min.js"></script>
- <script>
- baguetteBox.run('.tz-gallery');
- </script>
- <?php endwhile; ?>
- <?php
- endif;
- ?>
- <?php
- wp_die();
- }
- add_action('wp_ajax_load_posts_by_ajax2', 'load_posts_by_ajax_callback2');
- add_action('wp_ajax_nopriv_load_posts_by_ajax2', 'load_posts_by_ajax_callback2');
- ////
- js/custom-js.js
- var page = 2;
- jQuery(function($) {
- jQuery('body').on('click', '.loadmore2', function() {
- var data2 = {
- 'action': 'load_posts_by_ajax2',
- 'page': page,
- 'security': blog2.security
- };
- $.post(blog2.ajaxurl, data2, function(response2) {
- if(response2 != '') {
- jQuery('.roww').append(response2);
- page++;
- } else {
- jQuery('.loadmore2').hide();
- }
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement