Announcement

Collapse
No announcement yet.

Single post navigation in CPT

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Single post navigation in CPT

    Hi, can anyone please help with a CPT problem? I have a CPT 'artist' set up. I'm trying to add next/previous links to each single post. I've tried various snippets in functions, all of which produce the relevant div in the post footer but there are no links, despite there being 10 published CPTs.

    Here's the latest:

    Code:
    function prefix_navigation_links() {
        if ( is_singular('artist') ) {
        ?>
            <span class="nav-previous alignleft"><?php previous_post_link('%link', 'Previous Post', TRUE) ?></span>
            <span class="nav-next alignright"><?php next_post_link('%link', 'Next Post', TRUE) ?></span>
           <?php
        }
    }
    add_action('genesis_entry_footer', 'prefix_navigation_links' );
    The single-artist.php template contains this:

    Code:
    <?php
    
    remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
    
    genesis();
    
    ?>
    What am I missing? Should the post nav be in the template too?

  • #2
    Give this a try - worked for me on a CPT

    PHP Code:

    function prefix_navigation_links() {
     if ( is_singular('artist') ) {  ?>
          <span class="nav-previous alignleft"><?php previous_post_link('%link''Previous Post'?></span>
          <span class="nav-next alignright"><?php next_post_link('%link''Next Post'?></span>
        <?php
        
    }
    }
    add_action('genesis_entry_footer''prefix_navigation_links' );


    if you want the post 'Title' to be used as the link text - change the code in the span to this -

    PHP Code:

    <span class="nav-previous alignleft"><?php previous_post_link() ?></span>
    <span class="nav-next alignright"><?php next_post_link() ?></span>
    Last edited by andytc; 03-14-2017, 09:58 AM.

    Comment


    • #3
      Originally posted by Jaiji View Post
      .... What am I missing? Should the post nav be in the template too?

      'TRUE' is for normal posts from the same Category , maybe that's why it didn't work for you as this is a CPT and don't know if you have taxonomies attached

      Comment


      • #4
        Thanks andytc, much appreciated. I've already used a number of variants of the code you posted. It works fine, just not on the site in question. It seems I have some kind of plugin conflict. I've had to accept it for now as I don't have any more time to spend on it.

        Comment

        Working...
        X