[Resolved] Double pagination on post

Home Forums Support [Resolved] Double pagination on post

Home Forums Support Double pagination on post

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #886724
    Todd

    Hi Tom / all–

    You’ve helped a bit on this is in the past, so hopefully you have an idea here. I’m not sure when it broke, unfortunately, and I can’t seem to figure out the fix. My blog is a webcomic, where it’s important to have pagination above and below the post. I have this, but I somehow now have double pagination below the post.

    If you go to the main page of the site, you’ll see the pagination is correct. But if you click any of the pagination links (which takes you to a post) you’ll see the double pagination below the post.

    This is what’s in my child theme functions.php:

    <?php
    
    add_action( 'generate_before_main_content', function() {
        if ( function_exists( 'previous_post_link' ) && function_exists( 'next_post_link' ) ) {
    		echo '<div class="post-navigation">';
    		echo  previous_post_link(); //Older Link using max_num_pages
    		echo  next_post_link(); //Newer Link using max_num_pages
    		echo '</div>'; 
        }
    } );
    
    add_action( 'generate_after_main_content', function() {
        if ( function_exists( 'previous_post_link' ) && function_exists( 'next_post_link' ) ) {
    		echo '<div class="post-navigation">';
    		echo  previous_post_link(); //Older Link using max_num_pages
    		echo  next_post_link(); //Newer Link using max_num_pages
    		echo '</div>'; 
        }
    } );
    
    add_filter( 'next_post_link', function( $output, $format, $link, $post ) {
    	
    	$currentID = get_the_ID();
      	$args = array(
    	  	'numberposts' => 1,
    	  	'order'    => 'ASC',
    	  	'orderby' => 'rand',
    	  	'post__not_in' => array( $currentID ),
    	);
      
        $random_post = get_posts( $args );
    	
        if ( ! $post ) {
           	  $next = sprintf(
            '<a class="next-post" href="%1$s" title="%2$s"></a>',
            get_permalink( $post ),
            $post->post_title
    	);
    
    	  $random_post = sprintf(
            '<a class="random-post" href="%1$s" title="%2$s"></a>',
            get_permalink( $random_post[0]->ID ),
            get_the_title( $random_post[0]->ID )
        );
    	
    	$last_post = get_posts( 'numberposts=1' );
    
        $last_post = sprintf(
            '<a class="last-post" href="%1$s" title="%2$s"></a>',
            get_permalink( $last_post[0]->ID ),
            get_the_title( $last_post[0]->ID )
        );
    	      return $random_post . $next . $last_post;
        }
    	
    	else {
    		  $next = sprintf(
            '<a class="next-post" href="%1$s" title="%2$s"></a>',
            get_permalink( $post ),
            $post->post_title
        );
      
        $random_post = sprintf(
            '<a class="random-post" href="%1$s" title="%2$s"></a>',
            get_permalink( $random_post[0]->ID ),
            get_the_title( $random_post[0]->ID )
        );
        
    	$last_post = get_posts( 'numberposts=1' );
    
        $last_post = sprintf(
            '<a class="last-post" href="%1$s" title="%2$s"></a>',
            get_permalink( $last_post[0]->ID ),
            get_the_title( $last_post[0]->ID )
        );
    	   return $random_post . $next . $last_post;
    	}
    	
    }, 10, 4 );
    
    add_filter( 'previous_post_link', function( $output, $format, $link, $post ) {
        if ( ! $post ) {
            $prev = sprintf(
            '<a class="previous-post" href="%1$s" title="%2$s"></a>',
            get_permalink( $post ),
            $post->post_title
        );
    
     $latest_post = get_posts( 'numberposts=1&order=ASC' );
    
        $latest_post = sprintf(
            '<a class="latest-post" href="%1$s" title="%2$s"></a>',
            get_permalink( $latest_post[0]->ID ),
            get_the_title( $latest_post[0]->ID )
        );
    	
    	    return $latest_post . $prev;
        }
      else{
        $prev = sprintf(
            '<a class="previous-post" href="%1$s" title="%2$s"></a>',
            get_permalink( $post ),
            $post->post_title
        );
    
     $latest_post = get_posts( 'numberposts=1&order=ASC' );
    
        $latest_post = sprintf(
            '<a class="latest-post" href="%1$s" title="%2$s"></a>',
            get_permalink( $latest_post[0]->ID ),
            get_the_title( $latest_post[0]->ID )
        );
    	
        return $latest_post . $prev;
      }
    }, 10, 4 );

    Thanks!

    #886932
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this CSS:

    .inside-article .post-navigation {
        display: none;
    }

    Let me know πŸ™‚

    #887106
    Todd

    Thanks, Tom. That worked when I stuck it at the end of my CSS (though not at the beginning). So, I need to go through some of my spaghetti styling and figure out what is happening exactly. πŸ™‚

    #887109
    Tom
    Lead Developer
    Lead Developer

    This tool might help: https://jigsaw.w3.org/css-validator/

    Glad I could help πŸ™‚

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.