A
A
Alexey Chernov2016-05-23 23:16:19
CMS
Alexey Chernov, 2016-05-23 23:16:19

How to solve this problem of loading posts?

Good day, I ran into such a problem...
In the category page, I can’t connect ajax post loading in any way.
I took the sample code from truemisha.ru/blog/wordpress/ajax-pagination.html
The "load more" button just doesn't appear!
I think the problem is that for some reason max_num_page is always equal to 1.
Help, I don’t know how to do this

<?php get_header(); ?>

<?php 
global $wp_query;
echo $total_pages = $wp_query->max_num_pages; 
?>
<section class="big-photo"  style="background-image: url('<?php echo get_template_directory_uri(); ?>/img/photo-bg-ar.png');">
<div class="opacity-block col-5" style="margin: 66px 29.1%;">
      <p>Архив новостей</p>
    </div>
  </section>
<style type="text/css">
  .img-arhive{
    width: 270px;
    height: 180px;
    background-size: cover;
    margin-right: 25px;
    float: left;

  }
  p{
    font-family: GothamProRegular;
    font-size: 14px;
    color: #6b6b6b;
    line-height: 20px;
    margin-top: 8px;
  }
  .date-ar{
    color: #91a74a;
    font-size: 12px;
    font-family: Ubuntu;
    margin-top: 0;
    margin-bottom: 6px;
  }
  h2{
    font-size: 18px;
    color: #91a74a;
    font-family: GothamProBold;
    text-transform: uppercase;
    margin-top: 6px;
    margin-bottom: 8px;
  }

</style>

<section class="description-sec">
  <div class="some-content" id="loop">
  <?php
  $paged = get_query_var('paged') ? get_query_var('paged') : 1; 
  $args = array( 
                        'paged' => $paged,
                        'posts_per_page' => 5,
                        'orderby' => 'date', 
                        'category_name' => 'stati', 
                         );

                    $query = new WP_Query( $args );

                    // Цикл
                    if ( $query->have_posts() ) {
                        while ( $query->have_posts() ) {
                            $query->the_post();?>
                        <?php
                            $thumb_id = get_post_thumbnail_id();
                            $thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
                        ?>
                        <div class="col-12 post" style="margin-bottom: 35px;">
                          <a href="<?php the_permalink(); ?>"><div class="img-arhive" style=" background-image: url('<?php echo $thumb_url[0]; ?>'); "></div></a>
                          <p class="date-ar"><?php echo get_the_date(); ?></p>
                          <a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a>
                          <p><?php the_excerpt(); ?></p>
                        </div>
            <?php 
                              }
                            } 
                            wp_reset_postdata();?>


<?php if (  $wp_query->max_num_pages > 1 ) : ?>
  <script>
  var ajaxurl = '<?php echo site_url() ?>/wp-admin/admin-ajax.php';
  var true_posts = '<?php echo serialize($wp_query->query_vars); ?>';
  var current_page = <?php echo (get_query_var('paged')) ? get_query_var('paged') : 1; ?>;
  var max_pages = '<?php echo $wp_query->max_num_pages; ?>';
  </script>
  <div id="true_loadmore">Загрузить ещё</div>
<?php endif; ?>

  </div>    
    </div>
  </div>
    </div>
</section>



 <?php get_footer(); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Seva Sargsyan, 2016-05-23
@sevasargsyan

I have a creep plugin www.problogdesign.com/wordpress/load-next-wordpres...
Try putting this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question