0

I'm digging out on old question as no solution came out. How to limit page pagination

I'm looking for a way to limit pages on homepage and categories (archive.php). I have around 200k posts spread into about 50 categories. If I leave the default pagination, homepage has 20k pages. Then most categories have over 5k pages. This will send google in some long long loops... and each time a post is added (200/day) google will start again etc... when all I want is google to look into recent posts (this is a news website)

All I need is to let the visitors navigate threw the 10 first pages of each categories.

Is there a nice way for doing this?

I've tried different things described here without success. Limit number of pages in pagination

// this didn't work (beyond page 10 "next page" take us back to page 1)
function wpcodex_filter_main_search_post_limits( $limit, $query ) {     
  return 'LIMIT 0, 100'; 
} 
add_filter( 'post_limits', 'wpcodex_filter_main_search_post_limits', 10, 2 );

Removing the page links on page 10 would work for me even if you can manually enter page 11 and see page 11 posts... all I want is google not to find a link.

Deleting old posts is not an option, nor running a double query.

Thanks for your help

  • 1
    What about submitting a sitemap.xml to Google Webmaster Tools if you want to help Google better understand your site's structure ? Many plugins out there that help with building a sitemap.xml with various options. – birgire May 24 '16 at 17:39
  • Of cours I'll use sitemaps (news-sitemap too)... I'll need one that can manage sitemap indexes too as all posts won't fit in a single sitemap (limit 50k links) but I just don't need google to crawl extra 1000s of pages for nothing and would actually harm CPU (I'm currently getting 80k daily hits by google crawler). Giving the spider a link and it'll dig it... hard to stop it :) – Antony Gibbs May 24 '16 at 18:26
  • Looks like the only way is to use a "home made" pagination function... – Antony Gibbs May 24 '16 at 18:33
  • so you are trying to tell google how to crawl your site. This is exactly what sitemaps can do. Assuming you still want to have traffic to the older content this is also the only thing you can do – Mark Kaplun May 24 '16 at 19:05
  • google see anything that looks like a link, it goes for it... weather in sitemap or not. – Antony Gibbs May 24 '16 at 19:12
0

I was lucky, the theme used it's own function, so it was easy to override. Inspired by worpdress native get_the_posts_navigation (wp-includes/link-template.php) here is what I end up using:

function my_get_the_posts_navigation( $args = array() ) {
    $limit = 5;
    $navigation = '';

    // Don't print empty markup if there's only one page.
    if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
        $args = wp_parse_args( $args, array(
            'prev_text'          => __( 'Older posts' ),
            'next_text'          => __( 'Newer posts' ),
            'screen_reader_text' => __( 'Posts navigation' ),
        ) );


        $next_link = get_previous_posts_link( $args['next_text'] );

        $p = (get_query_var('paged')) ? get_query_var('paged') : 1;
        if ($p < $limit) {
          $prev_link = get_next_posts_link( $args['prev_text'] );
        } else {
          $prev_link = false;
        }

        if ( $prev_link ) {
            $navigation .= '<div class="nav-previous">' . $prev_link . '</div>';
        }

        if ( $next_link ) {
            $navigation .= '<div class="nav-next">' . $next_link . '</div>';
        }

        $navigation = _navigation_markup( $navigation, 'posts-navigation', $args['screen_reader_text'] );
    }

    return $navigation;
}

function my_the_posts_navigation( $args = array() ) {
    echo my_get_the_posts_navigation( $args );
}

// now override the theme pagination function
if ( ! function_exists( 'cactus_paging_nav' ) ) :
function cactus_paging_nav() {

    my_the_posts_navigation();
}
endif;
  • you simply don't understand how google crawls sites, this will not change anything, but from the beginning it was just an imaginary problem. – Mark Kaplun May 24 '16 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.