Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Marcushill746 on "Help to Add a 'Load More' Button to list of posts"

$
0
0

Hey,

So I've been putting together my own theme, and the only thing I have left to do is implement some kind of 'Load More Posts', infinite-scroll type thing to the page that displays my blog posts. Here is the code as it stands:

<?php

              // Grid Parameters
              $counter = 1; // Start the counter
              $grids = 5; // Grids per row
              $titlelength = 60; // Length of the post titles shown below the thumbnails

              // The Query
              $args=array (
                'post_type' => 'post',
                'posts_per_page' => -1
                );
              $the_query = new WP_Query($args);

              // The Loop
              while ( $the_query->have_posts() ) :
                $the_query->the_post();

              // Show all columns except the right hand side column
              if($counter != $grids) :
            ?>
              <div class="">
                <div class=" ">
                  <a class="" href="<?php the_permalink(); ?>" ><?php the_post_thumbnail(thumbnail); ?></a>
                </div><!-- .postimage -->
                <div class="">
                  <a class=""href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                    <p class="">
                      <?php if (mb_strlen($post->post_title) > $titlelength)
                        { echo mb_substr(the_title($before = '', $after = '', FALSE), 0, $titlelength) . ' ...'; }
                      else { the_title(); } ?>
                    </p>
                  </a>
                </div>

              </div><!-- .griditemleft -->
              <?php

              // Show the right hand side column
              elseif($counter == $grids) :
              ?>
              <div class="">
                <div class="">
                  <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(thumbnail); ?></a>
                </div><!-- .postimage -->
                <div class="">
                  <a class="" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                    <p class="">
                      <?php if (mb_strlen($post->post_title) > $titlelength)
                        { echo mb_substr(the_title($before = '', $after = '', FALSE), 0, $titlelength) . ' ...'; }
                      else { the_title(); } ?>
                    </p>
                  </a>
                </div>
              </div><!-- .griditemright -->

              <div class="clear"></div>
              <?php
                $counter = 0;
                endif;
                $counter++;
                endwhile;
                  wp_reset_postdata();
              ?>

(code implemented from here: http://pabstwp.de/wordpress-thumbnailseite-mit-artikelbildern/)

With posts_per_page set to -1 as it is right now, all the posts that I have ever posted will be loaded, which is less than ideal. Changing the number does of course limit the posts displayed, but I am not sure how to correctly implement pagination/infinite-scroll with the code that I have right now.

Can anyone point me in the right direction?


Viewing all articles
Browse latest Browse all 8245

Trending Articles