Skip to content

Instantly share code, notes, and snippets.

@raiden808

raiden808/blog_3 Secret

Last active January 22, 2019 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raiden808/e5fc513a8f6395a72b3c3d6b86cccae8 to your computer and use it in GitHub Desktop.
Save raiden808/e5fc513a8f6395a72b3c3d6b86cccae8 to your computer and use it in GitHub Desktop.
// ajax load more shortcode
function rda_blog_display_callback(){
$postsPerPage = 3;
$args = array(
'post_type' => 'post',
'posts_per_page' => $postsPerPage
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
echo "<div class='blog_wrapper'>";
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
echo "</div>";
} else {
// no posts found
}
echo '<a id="more_posts" href="#">Load More</a>';
}
add_shortcode( 'rda_blog_display', 'rda_blog_display_callback' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment