如何在单页中进行两个/多个分页的SEO链接标记?

时间:2015-10-06 11:50:25

标签: ruby-on-rails pagination seo

我在rails 4中编写了一个应用程序。在该应用程序中,我在单页中有两个分页' x(页面)'。参数如URL中的组和页面。

Url looks like:
https://example.com/x?page=2&group=4
Initial page:
https://example.com/x
If pagination page params, then
https://example.com/x?page=2
If paginating groups params, then
https://example.com/x?group=2
If paginating both,then
https://example.com/x?page=2&group=2
and so on.

我正在使用Kaminari宝石进行分页。在那个gem中,我使用了rel_next_prev_link_tags帮助器来显示prev / next的链接标记。

如何显示多个分页的链接标记?

2 个答案:

答案 0 :(得分:0)

我创建了一个自定义帮助程序来处理URL,并根据params创建分类链接标记。例如:在视图中,

pagination_link_tags(@pages,'page') for pages pagination
pagination_link_tags(@groups,'group') for groups pagination

def pagination_link_tags(collection,pagination_params)
    output = []
    link = '<link rel="%s" href="%s"/>'
    url = request.fullpath
    uri = Addressable::URI.parse(url)
    parameters = uri.query_values
    # Update the params based on params name and create a link for SEO
    if parameters.nil?
      if collection.next_page
        parameters = {}
        parameters["#{pagination_params}"] = "#{collection.next_page}"
        uri.query_values = parameters
        output << link % ["next", uri.to_s]
      end
    else
      if collection.previous_page
        parameters["#{pagination_params}"] = "#{collection.previous_page}"
        uri.query_values = parameters
        output << link % ["prev", uri.to_s]
      end
      if collection.next_page
        parameters["#{pagination_params}"] = "#{collection.next_page}"
        uri.query_values = parameters
        output << link % ["next", uri.to_s]
      end
    end
    output.join("\n").html_safe
  end

答案 1 :(得分:-1)

您无法显示搜索引擎的二维分页。在你的情况下,它看起来更像是分组/分类+分页。

像:

Group 1 pages:
https://example.com/x
https://example.com/x?page=2
https://example.com/x?page=3
Group 2 pages:
https://example.com/x?group=2
https://example.com/x?page=2&group=2
https://example.com/x?page=3&group=2