Site logo

Archived topic

pagination for GP custom page template

4 replies · Started by Manuela on August 16, 2019

Viewing posts 1–5 of 5

I have a custom template based on the page template of the Generate press theme.
This template displays all custom posts created by a user when that user is logged in. The custom posts display Advanced custom fields (ACF). All is well but I can’t figure out how can I use Generate press theme to add pagination to this template. If post_per_page is not set, 10 posts will display with no pagination links. I set the post_per_page 25 for now so the user can see all posts.

Below is a reduced version of my custom template. Thanks!

 <?php
 /*Template name: my guitars

 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package GeneratePress
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

get_header(); ?>

	<div id="primary" <?php generate_do_element_classes( 'content' ); ?>>
        <main id="main" <?php generate_do_element_classes( 'main' ); ?>>
            
			<?php
			/**
			 * generate_before_main_content hook.
			 *
			 * @since 0.1
			 */
            do_action( 'generate_before_main_content' );

if ( is_user_logged_in() ):

    global $current_user;
    wp_get_current_user();
         
            $guitar = new WP_Query(array(
			'post_type' => 'guitars',
			'nopaging'               => false,
    			'posts_per_page'         => '25',
                        'author' =>  $current_user->ID
            ));
        while ( $guitar->have_posts() ) : $guitar->the_post(); ?>

            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php generate_do_microdata( 'article' ); ?>>
				<div class="inside-article">
                     <div class="entry-content" itemprop="text">
                                            
                    <!--display post title -->  
					<header class="entry-header">

					</header><!-- .entry-header -->

                    <?php
                        /**
                         * generate_after_entry_header hook.
                         *
                         * @since 0.1
                         *
                         * @hooked generate_post_image - 10
                         */
                        do_action( 'generate_after_entry_header' );
                    ?>
                    <div class="details">
                        <!-- display ACF - custom post type guitar  -->	
    
                                        
                    </div>

                    <?php wp_link_pages( array(
                        'before' => '<div class="page-links">' . __( 'Pages:', 'generatepress' ),
                        'after'  => '</div>',
                    ) );
                    ?>
 
                    </div><!-- .entry-content -->

                        <?php
                        /**
                         * generate_after_entry_content hook.
                         *
                         * @since 0.1
                         *
                         * @hooked generate_footer_meta - 10
                         */
                        do_action( 'generate_after_entry_content' );

                        /**
                         * generate_after_content hook.
                         *
                         * @since 0.1
                         */
                        do_action( 'generate_after_content' );
                        ?>
				</div><!-- .inside-article -->
            </article>		
			
		<?php	endwhile; ?>
		<!-- Add pagination here? -->
	
		
<?php		
 else :

    echo "not logged in";

endif;           

			/**
			 * generate_after_main_content hook.
			 *
			 * @since 0.1
			 */
			do_action( 'generate_after_main_content' );
			?>
		</main><!-- #main -->
	</div><!-- #primary -->

	<?php
	/**
	 * generate_after_primary_content_area hook.
	 *
	 * @since 2.0
	 */
	do_action( 'generate_after_primary_content_area' );

	generate_construct_sidebars();

get_footer();

Note: I tried GP Show Posts, but couldn't limit the posts per logged in user.

Thanks Tom! I'll try that too!

No problem :)

This archived topic is closed to new replies.