This topic is: resolved
- This topic has 0 replies, 1 voice, and was last updated 5 years, 3 months ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- The forum ‘General Discussion’ is closed to new topics and replies.
These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.
Community Forums › Forums › Archived Forums › General Discussion › Add Pagination to Custom Loop
Tagged: custom, loop, pagination
Hi Community, apologies if this appears twice the first one seems to have disappeared.
I have a custom loop based on Carrie Dills tut on listing posts in categories, I'm using it on a galleries page for an artists site.
Having trouble figuring out how to add pagination to come in say after three galleries, I think I have to add it to the foreach because trying to add it to the loop produces multiple paginations at the end of each gallery.
Any help or guidance would be really appreciated!
<?php
/**
*
* Template Name: Gallery Archives
*
*/
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'lh_gallery_loop' );
/**
* Custom loop that display a list of galleries with corresponding posts.
*/
function lh_gallery_loop() {
// Grab all the galleries from the database that have posts.
$galleries = get_terms( 'galleries', 'orderby=name&order=ASC');
// Loop through galleries
foreach ( $galleries as $gallery ) {
// Display gallery name
echo '<h2 class="gallery-title">' . $gallery->name . '</h2>';
echo '<div class="gallery-list">';
// WP_Query arguments
$args = array(
'post_type' => 'work',
'tax_query' => array(
array(
'taxonomy' => 'galleries',
'field' => 'term_id',
'terms' => $gallery->term_id,
),
),
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$image = get_field( 'image' );
$sold = get_field( 'availability' );
$url = get_permalink();
$image = get_field( 'image' );
if ( $image ) : ?>
<a class="work-images" href="<?php echo $url; ?>"><img src="<?php echo esc_url( $image['url'] ); ?>" alt="<?php echo esc_attr( $image['alt'] ); ?>" />
<?php endif;
// Add red dot to work if sold
if ( $sold ) :
echo '<span class="dot"></span><p class="gallery-title gallery-title-sold">' . get_the_title() . '</p>' ?>
<?php else: ?>
<?php echo '<p class="gallery-title gallery-title-available">' . get_the_title() . '</p>' ?>
<?php endif; ?>
</a>
<?php
} // End while
} // End if
echo '</div>';
// Restore original Post Data
wp_reset_postdata();
} // End foreach
}
// Start the engine.
genesis();
http://onlyonlocal.com
© 2025 WPEngine, Inc.