2011-02-13 01:52:55 8 Comments
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!
Related Questions
Sponsored Content
1 Answered Questions
[SOLVED] Trying to Create a PHP Variable for post_type that can be referenced Site Wide
- 2018-07-26 12:19:55
- Katie R.
- 39 View
- 0 Score
- 1 Answer
- Tags: custom-post-types php loop variables query-variable
1 comments
@Bainternet 2011-02-13 13:36:02
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
@AlxVallejo 2012-10-24 17:35:04
This answer is a goldmine that you really can't find in textbooks
@Bram Vanroy 2015-02-27 11:03:05
I know that this is an old answer, but it's still relevant to me. I do wonder why the
return false
is necessary, as you are calling it on the click event of a button, to which there's no form related. I think you could leave it out. Also, how doescheck_ajax_referer
know what to check, as you are not using any nonce fields? And what iswp-ajax-response
?