将无限滚动添加到Wordpress

时间:2018-11-28 10:41:03

标签: wordpress infinite-scroll

一段时间以来,我对Wordpress还是很陌生,因为我开始使用wordpress进行分页,现在我想用无限滚动替换nomarlae ima d wordpress,但尝试了一些指南,但是我不能有人可以解释执行此操作的步骤。

 <main class="container mt-6 main-content ">
    <div class="row">
        <?php
            $current_page = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $per_page = '5';
            $args = array(
            'post_type' => 'eventi',
            'posts_per_page' => $per_page,
            'paged' => $current_page,
            'tax_query' => array(
             array(
                    'taxonomy' => 'evento',
                    'field' => 'slug',
                    'terms'    => array( 'evento'),
                  )
                )
            );
            // La Query
            $so_the_query = new WP_Query( $args );
        ?>
            <div class="col-sm-12 col-md-12 col-lg-12 ml-sm-auto mr-sm-auto">

            <?php if(has_post_thumbnail()) {} else { ?>
            <h1 class="entry-title my-4 text-center"> <?php the_title(); ?> </h1>
            <?php } ?>

            <?php if ($so_the_query->have_posts()) : while ($so_the_query->have_posts()) : $so_the_query->the_post(); ?>            
                  <ul class="event-list mt-4">
                    <li>
                        <time datetime="2014-07-20">
                            <span class="day"><?php the_field('giorno'); ?></span>
                            <span class="month"><?php the_field('mese_abbreviato'); ?></span>
                            <span class="year"><?php the_field('anno'); ?></span>
                            </time>
                            <?php the_post_thumbnail('so_single', array('class' => ' img-fluid', 'alt' => get_the_title() )) ?>
                            <div class="info">
                            <h2 class="title"><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
                            <div class="desc"><a href="<?php the_permalink();?>"><?php the_excerpt();?></a></div>
                            </div>
                    </li>
                </ul>

        <?php endwhile; ?>

        <div class="pagination col-sm-12 col-md-12 col-lg-12 ml-sm-auto mr-sm-auto">    

            <?php
                global $so_the_query;

                $big = 999999999; 

                echo paginate_links( array(
                    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                    'format' => '?paged=%#%',
                    'current' => max( 1, get_query_var('paged') ),
                    'total' => $so_the_query->max_num_pages
                ) );
             ?>
        </div>

        <?php else : ?>         
                <div class="pagination col-sm-12 col-md-6 col-lg-10 ml-sm-auto mr-sm-auto"> 
                <h2 class="center">Nessun Evento presente, prova tra un po di tempo!</h2>
                </div>    
        <?php endif; ?>
         </div> 
    </div>
</main>

<?php get_footer(); ?>

0 个答案:

没有答案