Hi, I have run Screaming Frog and its brought up a sequence error for pagination. I have been struggling to rank for this page and I want to eliminate any potential errors.
This is the reply i received from them on what i need to do.
This shows URLs that have an error in the rel=”next” and rel=”prev” HTML link elements sequence. This check ensures that URLs contained within rel=”next” and rel=”prev” HTML link elements reciprocate and confirm their relationship in the series.
You’ll need to amend pages to ensure the sequence is maintained and the relationship is kept.
The question of how to do this is my problem. I have the PHP code but no idea on what I need to change.
Below is a file called pagination.php
<?php global $the_query; ?>
<?php if ( $the_query ) { ?>
<?php if ( $the_query->max_num_pages > 1 ) : ?>
<div class="clearboth"></div>
<?php /*if(is_plugin_active('wp-pagenavi/wp-pagenavi.php')) {
echo '<div class="pagination-wrapper">';
wp_pagenavi( array( 'query' => $the_query ) );
echo '</div>';
echo '<div class="clearboth"></div>';
} else { */?>
<div class="pagination-wrapper">
<p class="clearfix">
<span class="fl prev-pagination"><?php next_posts_link( esc_html__( '← Older posts', 'yachtcharter' ), $the_query->max_num_pages ); ?></span>
<span class="fr next-pagination"><?php previous_posts_link( esc_html__( 'Newer posts →', 'yachtcharter' ), $the_query->max_num_pages ); ?></span>
</p>
</div>
<?php //} ?>
<?php endif; ?>
<?php } else {
if ( $wp_query->max_num_pages > 1 ) : ?>
<div class="clearboth"></div>
<?php /*if(is_plugin_active('wp-pagenavi/wp-pagenavi.php')) {
echo '<div class="pagination-wrapper">';
wp_pagenavi();
echo '</div>';
echo '<div class="clearboth"></div>';
} else { */?>
<div class="pagination-wrapper">
<p class="clearfix">
<span class="fl prev-pagination"><?php next_posts_link( esc_html__( '← Older posts', 'yachtcharter' ) ); ?></span>
<span class="fr next-pagination"><?php previous_posts_link( esc_html__( 'Newer posts →', 'yachtcharter' ) ); ?></span>
</p>
</div>
<?php // } ?>
<?php endif; ?>
<?php } ?>
Also i have this code which i found in the function.php file
// Add link rel next/prev for boats to head
function add_link_rel_head_boats() {
// If its the boats page
if( is_page( 'boats' ) ) {
// If its the first boats page
if( !is_paged() ) {
echo '<link rel="next" href="' . get_permalink() . 'page/2/">';
} else { // Its one of the boat paginated pages
// Get the current page number
$current_page_number = (int)get_query_var('paged');
// Calculate the previous page number
$previous_page_number = $current_page_number - 1;
// Calculate the next page number
$next_page_number = $current_page_number + 1;
// Insert previous page number
echo '<link rel="prev" href="' . get_permalink() . 'page/' . $previous_page_number . '/">';
// Count the total boats (bit of a faff but it's because the boats are displayed through shortcode)
$args = array(
'posts_per_page' => -1,
'post_type' => 'ycbe_boat',
'post_status' => 'publish',
);
$boats = get_posts( $args );
$boats_count = count( $boats );
// 12 is the amount of boats per page, unfortunately this has to be hardcoded as the boats 'per page' setting is set on shortcode. Therefore if the value changes in the shortcode it should be changed to match here to ensure that the next link doesn't appear when there is no page
$max_page_number = (int)ceil( $boats_count / 12 ); // Boats count divided by 12 rounded up to nearest whole number
// If current page number is not the max page
if( $current_page_number !== $max_page_number ) {
// Insert next page number
echo '<link rel="next" href="' . get_permalink() . 'page/' . $next_page_number . '/">';
}
}
}
}
add_action( 'wp_head', 'add_link_rel_head_boats' );
Any advise would be great.
Thanks
Danny