PHP code example of motiontactic / wp-ajax

1. Go to this page and download the library: Download motiontactic/wp-ajax library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

motiontactic / wp-ajax example snippets



motiontactic\WP_AJAX;

class BlogFeed extends WP_AJAX
{
	protected function getQueryArgs()
	{
		return [
			'post_status'    => 'publish',
			'post_type'      => 'post',
			'posts_per_page' => 1,
			'paged'          => $_REQUEST[ 'page' ],
		];

	}
}

new BlogFeed( [
	'action'                   => 'get_posts',
	'output_template'          => 'partials.blog-posts',
	'pagination_template'      => 'partials.blog-pagination',
	'pagination_pages_to_show' => 9,
	'

$args = [
	'action'                   => 'get_posts',  //ajax action name used by JS to address this query
	'output_template'          => false,        //blade template location for the output html
	'pagination_template'      => false,        //blade template location for the pagination html
	'pagination_pages_to_show' => 9,            //Used in the pagination array creation
	'

motiontactic\WP_AJAX::arrayOfPages( 6, 100, 9 );
blade
@if( $current_page !== 1)
  <a href="?paged={{ $current_page - 1 }}" class="prev-arrow nav-arrow"
     data-paged="{{ $current_page - 1 }}">
    <div class="pagination-arrow prev">
      <
    </div>
  </a>
@endif
@foreach($pages as $page)
  @if($page === 'E')
    <p class="page width-auto pagination-spacing">
      ...
    </p>
  @else
    <a href="?paged={{ $page }}"
       class="page width-auto {{ $page === $current_page ? 'current' : '' }}"
       data-paged="{{ $page }}">{{ $page }}</a>
  @endif
@endforeach
@if( $current_page !== $max_pages )
  <a href="?paged={{ $current_page + 1 }}" class="next-arrow nav-arrow"
     data-paged="{{ $current_page + 1 }}">
    <div class="pagination-arrow next">
      >
    </div>
  </a>
@endif