I have a list of the most recent post titles in sidebar.php
. Here is an example of how that code looks:
<?php $args = array('posts_per_page' => 20); ?>
<?php $sidebar = new WP_Query($args); ?>
<?php if ( $sidebar->have_posts() ) : ?>
<?php while ( $sidebar->have_posts() ) : $sidebar->the_post(); ?>
<div class="story">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_title(); ?> - <?php the_time("F j, Y h:i A"); ?>
</a>
</div>
<?php endwhile; ?>
<?php endif; ?>
That part works perfectly. It displays the 20 latest post titles and post times wrapped in permalinks. However, I am trying to do a bit more. I want to create a load more button at the bottom to fetch the next 20 post titles. I know my jQuery and that is not the issue.
I need help with figuring out how to create a custom loop in a new custom .php
template file that only generates the html above. That file needs to be able to accept a parameter for a page number, so that my javascript
can fetch an incremented URL each time.
I would appreciate any help, thanks!
you can wrap your function and hook it to ajax call like this:
then add this to your sidebar function at the end
and there you go, oh wait you need to add wp-ajax-response so
and you are set