我需要将页码添加到我的 /collections/ 元标题和描述中 - 对于分页页面。我怎样才能通过代码实现它?
例如:第一页的标题将类似于“我们的标题”,如果我们转到第二页,我们应该有“我们的标题 - 第 2 页”。目前,所有带分页的页面都具有第一个页面的标题。
不知道您使用的是哪个主题,但这已经是 Shopify Debut 主题的一部分。负责的代码位于 theme.liquid.
{%- capture seo_title -%}
{%- if request.page_type == 'search' and search.performed == true -%}
{{ 'general.search.heading' | t: count: search.results_count }}: {{ 'general.search.results_with_count' | t: terms: search.terms, count: search.results_count }}
{%- else -%}
{{ page_title }}
{%- endif -%}
{%- if current_tags -%}
{%- assign meta_tags = current_tags | join: ', ' -%} – {{ 'general.meta.tags' | t: tags: meta_tags -}}
{%- endif -%}
{%- if current_page != 1 -%}
– {{ 'general.meta.page' | t: page: current_page }}
{%- endif -%}
{%- assign escaped_page_title = page_title | escape -%}
{%- unless escaped_page_title contains shop.name -%}
– {{ shop.name }}
{%- endunless -%}
{%- endcapture -%}
<title>{{ seo_title | strip }}</title>
您可以使用上面的代码。否则对于您的具体情况,您只需要这个条件。
{%- capture seo_title -%}
{{ page_title }}
{%- if current_page != 1 -%}
– Page - {{ current_page }}
{%- endif -%}
{%- endcapture -%}
<title>{{ seo_title | strip }}</title>
您在名为 current_page 的变量中拥有当前页码,您可以将其用于您的条件。