-
-
Save raiden808/e5fc513a8f6395a72b3c3d6b86cccae8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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