• 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 Conditional Pagination to Pages

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 › Adding Conditional Pagination to Pages

This topic is: not resolved

Tagged: conditional, next_post_link, pagination, previous_post_link

  • This topic has 2 replies, 2 voices, and was last updated 8 years, 10 months ago by Dan.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • May 23, 2014 at 3:28 am #106465
    Dan
    Participant

    Hi there,
    Could someone help me figure out what I need to add / edit in this code block to set up pagination conditionally on 4 pages please?

    //Adds Pagination to Story Pages
    add_action('genesis_after_entry', 'custom_post_nav', 5); 
    function custom_post_nav(){ 
    if ( is_page(array(176,184,192,196))) { ?>   
    <div class="post-nav"> 
    <div class="prev-post-nav"> 
    <?php previous_post_link(); ?> 
    </div>
    <div class="next-post-nav"> 
    <?php next_post_link(); ?> 
    </div><hr> 
    </div> 
    <?php 
    }
    }

    The issue I have is that the first page in the series picks up and displays the previous link of the page created chronologically prior to it, despite that page (ID 82), not being in the array.

    (Note: the last page in the array does not display the link of the next page - go figure!)

    Many thanks!

    (Site not public yet, so no URL. Can provide via PM if needed though)

    May 24, 2014 at 1:21 am #106573
    Tom
    Participant

    If you are seeking single post navigation, you can place the P/N links using this code, adapted from a navigation post by @braddalton:

    add_action( 'genesis_entry_content', 'kp_single_post_nav', 10 );
    
    function kp_single_post_nav() {
    
         if ( ! is_page( array( 176, 184, 192, 196 )  )  )
            return;
    
        echo '<div class="pagination-previous alignleft">';
        previous_post_link('%link', 'Previous Post', FALSE);
        echo '</div>';
    
        echo '<div class="pagination-next alignright">';
        next_post_link('%link', 'Next Post', FALSE);
        echo '</div>';
    
    }

    I made this work, but not reliably in brief testing, likely due to chronological page creation. Anomalies, as you also found.

    For your code and this, you could hide the links with CSS similar to:

    .page-id-497 .pagination-previous a {
        display: none;
    }

    If you are seeking real pagination, why don't you simply use <!--nextpage--> in the pages where you want to trigger pagebreaks within the page/post? The pagination happens automatically, is reliable and reusable without code.


    Choose your next site design from over 350 Genesis themes.
    [ Follow me: Twitter ] [ Follow Themes: Twitter ] [ My Favourite Webhost ]

    May 24, 2014 at 7:08 am #106587
    Dan
    Participant

    Hi Tom,
    Many thanks for your help!

    I didn't think to try hide that link with CSS, so I'll go play around, see if I can't get that to do the job.

    🙂

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 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