• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Add Pagination to Custom Loop

Welcome!

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.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Add Pagination to Custom Loop

This topic is: resolved

Tagged: custom, loop, pagination

  • This topic has 0 replies, 1 voice, and was last updated 2 years, 5 months ago by LanceHillier.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • August 12, 2020 at 8:55 pm #500547
    LanceHillier
    Participant

    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
  • Author
    Posts
Viewing 1 post (of 1 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble