Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function blog_post_item() {
- ob_start();
- ?>
- $list_post = array(
- 'post_type' => 'post',
- 'posts_per_page' => 6,
- 'post_status' => 'publish',
- 'order_by' => 'slug',
- 'order' => 'DESC',
- );
- $list_query = new WP_Query( $list_post );
- ?>
- <div id="blog-all-item" class="row">
- <?php
- if( $list_query->have_posts() ) {
- while( $list_query->have_posts() ) {
- $list_query->the_post();
- $num = $list_query->post_count;
- $thumb2 = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' ); ?>
- <div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12 blog-item-wrap">
- <a class="post-list-item" href="<?php echo get_permalink(); ?>">
- <div class="post-list-item-wrapper">
- <div class="item-post-thumbnail">
- <img class="lazyload" data-src="<?php echo $thumb2[0]; ?>">
- </div>
- <div class="item-post-content">
- <h2><?php echo the_title(); ?></h2>
- <span class="post-date"><?php the_time('j F Y'); ?></span>
- <p><?php echo wp_trim_words( get_field('introduce_text'), 15 );?></p>
- </div>
- </div>
- </a>
- </div>
- <?php
- }
- }
- ?>
- </div>
- <?php
- $total = wp_count_posts()->publish;
- ?>
- <div class="center-btn">
- <?php
- if ($total > 6) {
- ?><div id="more_posts">Load More</div><?php
- }
- ?>
- </div>
- <?php
- return ob_get_clean();
- }
- add_shortcode('blog-post-item', 'blog_post_item');
- function more_post_ajax(){
- $ppp = (isset($_POST["ppp"])) ? $_POST["ppp"] : 6;
- $page = (isset($_POST['pageNumber'])) ? $_POST['pageNumber'] : 0;
- header("Content-Type: text/html");
- $args = array(
- 'suppress_filters' => true,
- 'post_type' => 'post',
- 'posts_per_page' => $ppp,
- 'paged' => $page,
- );
- $loop = new WP_Query($args);
- $out = '';
- if ($loop -> have_posts()) : while ($loop -> have_posts()) : $loop -> the_post();
- $thumb2 = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
- $out .= '<div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12 blog-item-wrap">
- <a class="post-list-item" href="'.get_the_permalink().'">
- <div class="post-list-item-wrapper">
- <div class="item-post-thumbnail">
- <img class="lazyload" data-src="'.$thumb2[0]. '">
- </div>
- <div class="item-post-content">
- <h2>'.get_the_title().'</h2>
- <span class="post-date">'.get_the_time('j F Y').'</span>
- <p>'.wp_trim_words( get_field('introduce_text'), 15 ).'</p>
- </div>
- </div>
- </a>
- </div>';
- endwhile;
- endif;
- wp_reset_postdata();
- die($out);
- }
- add_action('wp_ajax_nopriv_more_post_ajax', 'more_post_ajax');
- add_action('wp_ajax_more_post_ajax', 'more_post_ajax');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement