WordPress

Jak dodać Ajax do tej paginacji, którą zrobiłem?

  • 13 września, 2019
  • 3 min read
Jak dodać Ajax do tej paginacji, którą zrobiłem?


To jest mój plik funkcji

add_action( 'wp_ajax_homekong_pagination', 'homekong_pagination' );
add_action( 'wp_ajax_nopriv_homekong_pagination', 'homekong_pagination' ); 
function homekong_pagination($pages="", $range = 2)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<div class="paginations">";
        echo "<nav class="page-navigation">";
            echo "<ul id='pagination' class="pagination">";
                    if($paged > 2 && $paged > $range+1 && $showitems < $pages)
                        echo "<li class="page-item"><a aria-current="page" class="page-numbers page-link prev" href="".get_pagenum_link(1)."">PREVIOUS</a></li>";
                        if($paged > 1 && $showitems < $pages)
                            echo "<li class="page-item"><a class="page-numbers page-link" href="".get_pagenum_link($paged - 1).""><span class="dashicons dashicons-arrow-left-alt"></span></a></li>";
                        for ($i=1; $i <= $pages; $i++)
                        {
                            if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
                                {
                                    echo ($paged == $i)? "<li class="page-item"><a class="page-numbers page-link current">".$i."</a></li>" : "<li class="page-item"><a class="page-numbers page-link" href="".get_pagenum_link($i)."">".$i."</a></li>";
                                }
                        }
                        if ($paged < $pages && $showitems < $pages)
                            echo "<li class="page-item"><a class="page-numbers page-link" href="" .get_pagenum_link($paged + 1).""><span class="dashincon dashicons-arrow-right-alt"></span></a></li>";
                if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages)
                    echo "<li class="page-item"><a class="next page-numbers page-link" href="".get_pagenum_link($pages)."">NEXT</a></li>";
                echo "</ul>";
            echo "</nav>";
        echo "</div>";
}
exit();
}

To jest mój kod frontonu, w którym chciałbym wprowadzić zmiany.


<div id="blogs" class="blog-items">
    <div class="row">
        <?php
                        // args
                        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
                        $args = array(
                        'order_by' => 'publish_date',
                        'order' => 'desc',
                        'post_type' => 'blogs',
                        'paged' => $paged,
                        );
                        // get results
                        $the_query = new WP_Query( $args );
                        // The Loop
                        ?>
        <?php if( $the_query->have_posts() ): ?>
        <?php $counter = 0;?>
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <div class="col-lg-6">
            <div class="blog-item">
                <div class="img-thumb">
                    <?php the_post_thumbnail();?>
                </div>
                <div class="blog-text">
                    <div class="blog-cat">
                        <label for="">
                            <?php echo blog_categories_terms($post->ID, 'blog-category');?>
                        </label>
                    </div>
                    <a href=" the_permalink();?>">
                        <h3 class="blog-title">
                            <?php the_title();?>
                        </h3>
                    </a>
                    <div class="blog-date">
                        <?php echo get_the_date();?>
                    </div>
                </div>
            </div>
        </div>
        <?php endwhile; ?>
        <?php endif; ?>
        <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>
        <!-- end row  -->
    </div>
    <!-- end blog items  -->

Jak dodać ajax do paginacji? Nie mogę wymyślić sposobu, aby to zrobić

Warto przeczytać!  wtyczki - Wybór produktu zmiennego


Źródło