I have created a loop that basically gets all "featured Images" (post thumbnails) & page titles from each page in my WordPress theme and displays them on the front page. That works great, here is the code so far:
<?php $args = array(
'sort_order' => 'asc',
'sort_column' => 'menu_order',
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'meta_key' => '',
'meta_value' => '',
'authors' => '',
'child_of' => $post->ID,
'parent' => -1,
'exclude_tree' => '',
'number' => '',
'offset' => 0,
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages($args);
?>
<section id="blog">
<div class="posts">
<?php foreach ( $pages as $page ) : ?>
<?php
$background = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'full' );
?>
<div class="small post" style="background-image: url( '<?php echo $background[0]; ?>' );">
<a href="<?php the_permalink( $page->ID ); ?>">
<span class="inside">
<h2><?php echo apply_filters( 'the_title', $page->post_title, $page->ID ); ?></h2>
</span>
</a>
</div>
<?php endforeach; ?>
</div>
</section>
Problem: Because I have 10+ pages on my site, This code outputs all featured images at once. That is too much.
What I need: I would like to limit what I loop out to 3 featured images and then be able to click "View More" to load another "x" amount of featured images.
I have found a perfect example of what I need here: jQuery load first 3 elements, click "load more" to display next 5 elements But it just does not work for me, I am not sure if its because using a JQuery solution for a PHP loop is not the best solution.