• 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

adding pagination to custom post type page template

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 › Design Tips and Tricks › adding pagination to custom post type page template

This topic is: not resolved

Tagged: post navigation

  • This topic has 6 replies, 3 voices, and was last updated 9 years, 11 months ago by Brad Dalton.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • February 19, 2016 at 7:48 pm #179435
    dmcleod87
    Member

    hi all,

    working on a new portfolio website and have setup a CPT named 'portfolio'. I have also created a custom page template for each portfolio item. what i want to do is to add pagination to the bottom of this page to in order to cycle through the other portfolio items. below is the code i've used for my custom page template. the theme is based on the Genesis Sample theme.

    can someone point me in the right direction? i've tried a few solutions that i found online but nothing seemed to work...thanks!

    <?php
    /*
    Template Name: Portfolio Item
    */
    
    remove_action('genesis_loop', 'genesis_do_loop');
    
    add_action('genesis_loop', 'custom_loop');
    
    function custom_loop() {
    
        global $paged;
        $args = array('post_type' => 'portfolio'); ?>
    
    	<article itemtype="http://schema.org/CreativeWork" itemscope="itemscope" class="post-<?php print $pageid; ?> page type-page status-publish entry">
    	<div class="entry-content" itemprop="text">
    
    	<div class="custom-page-content">
    	<?php if(have_posts()) : while(have_posts()) : the_post();
    
    	echo '<div class="intro-text-wrapper">';
    
    	/* Display the page title */
    	echo '<h1 class="page-title"> ' . get_field('project_page_title') . ' </h1>';
    
    	/* The following code displays the Advanced Custom Fields meta boxes */
    	echo '<div class="intro-text"> ' . get_field('project_intro_text') . ' </div>';
    
    	echo '</div>';
    
    	/* Show page content below intro text */
    	do_action( 'genesis_entry_content' );
    
    	endwhile; endif; ?>
    
    	</div></div></article>
    
    	<?php }
    
    genesis();
    February 20, 2016 at 12:57 am #179443
    Brad Dalton
    Participant

    Is this an archive page or a single-portfolio.php?

    For single posts/cpt you would use previous_post_link and next_post_link for post navigation
    For archives you would use the_posts_pagination for Previous/next page navigation


    Tutorials for StudioPress Themes.

    February 20, 2016 at 2:05 am #179451
    dmcleod87
    Member

    hi brad,

    it's a single-portfolio.php template. is this snippet what i would be looking for? https://wpbeaches.com/add-custom-post-type-navigation-links-in-genesis/

    i tried it just then and no luck.

    February 25, 2016 at 5:00 pm #179925
    dmcleod87
    Member

    figured it out. using the tutorial i mentioned above and following brad's advice, i added parts of the snippet to my custom template, rather than to functions.php

    hope this helps someone else in the future!

    <?php
    /*
    Template Name: Portfolio Item
    */
    
    remove_action('genesis_loop', 'genesis_do_loop');
    
    add_action('genesis_loop', 'custom_loop');
    
    function custom_loop() {
    
        global $paged;
        $args = array('post_type' => 'portfolio');
    
    	genesis_markup( array(
    			'html5'   => '<div %s>',
    			'xhtml'   => '<div class="navigation">',
    			'context' => 'adjacent-entry-pagination',
    	) )
    
        ?>
    
    	<article itemtype="http://schema.org/CreativeWork" itemscope="itemscope" class="post-<?php print $pageid; ?> page type-page status-publish entry">
    	<div class="entry-content" itemprop="text">
    
    	<div class="custom-page-content">
    	<?php if(have_posts()) : while(have_posts()) : the_post();
    
    	echo '<div class="intro-text-wrapper">';
    
    	/* Display the page title */
    	echo '<h1 class="page-title"> ' . get_field('project_page_title') . ' </h1>';
    
    	/* The following code displays the Advanced Custom Fields meta boxes */
    	echo '<div class="intro-text"> ' . get_field('project_intro_text') . ' </div>';
    
    	echo '</div>';
    
    	/* Show page content below intro text */
    	do_action( 'genesis_entry_content' );
    
    	// Add pagination Portfolio Post Type
    	echo '<div class="pagination-previous alignleft">';
    	previous_post_link();
    	echo '</div>';
    
    	echo '<div class="pagination-next alignright">';
    	next_post_link();
    	echo '</div>';
    
    	echo '</div>';
    
    	endwhile; endif; ?>
    
    	</div></div></article>
    
    	<?php }
    
    genesis();
    February 26, 2016 at 2:08 am #179964
    Brad Dalton
    Participant

    Good stuff. Genesis do have a function for single post navigation however it includes the conditional

     is_singular('post')

    If they changed that to

    is_singular()

    it could also be used on CPT's

    /**
     * Display links to previous and next post, from a single post.
     *
     * @since 1.5.1
     *
     * @return null Return early if not a post.
     */
    function genesis_prev_next_post_nav() {
    
    	if ( ! is_singular() )  
    		return;
    
    	genesis_markup( array(
    		'html5'   => '<div %s>',
    		'xhtml'   => '<div class="navigation">',
    		'context' => 'adjacent-entry-pagination',
    	) );
    
    	echo '<div class="pagination-previous alignleft">';
    	previous_post_link();
    	echo '</div>';
    
    	echo '<div class="pagination-next alignright">';
    	next_post_link();
    	echo '</div>';
    
    	echo '</div>';
    
    }

    Tutorials for StudioPress Themes.

    February 27, 2016 at 9:17 am #180060
    himansh
    Member

    Hi, i tried to add post navigation to single posts, using the snippet provided here : http://my.studiopress.com/snippets/entry-content/

    but its just showing link to the post - "Hello World" only after entry.

    Any Hint why its behaving like this ?

    Thanks in advance

    February 27, 2016 at 11:01 am #180071
    Brad Dalton
    Participant

    Must be the first post. Check the 2nd post which should includes links to both the previous and next post.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Design Tips and Tricks’ 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

© 2026 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