商店名称的 Shopify Liquid If 语句
Shopify Liquid If Statement for Shop Name
我通过 theme.liquid 文件中的以下语句将我的品牌名称或商店名称添加到我所有的 URL 中。我想排除所有博客或文章页面。这意味着那些 URL 上没有商店名称,这是管道和代码。
| {{ shop.name }}
原码
{%- capture seo_title -%}
{%- if template == '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>
我一直在尝试围绕以下内容放置另一个 if 语句,但我还没有成功。
{%- assign escaped_page_title = page_title | escape -%}
{%- unless escaped_page_title contains shop.name -%}
| {{ shop.name }}
{%- endunless -%}
这是我试过的代码,有没有更好的方法来实现它,因为我不能完全让它工作。
尝试的代码
{%- capture seo_title -%}
{%- if template == '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 -%}
{%- if (template == "blog" or template == "article") and current_tags contains '_NOINDEX' -%}
{%- assign escaped_page_title = page_title | escape -%}
{%- unless escaped_page_title contains shop.name -%}
{%- endunless -%}
{%- else -%}
{%- assign escaped_page_title = page_title | escape -%}
{%- unless escaped_page_title contains shop.name -%}
| {{ shop.name }}
{%- endunless -%}
{%- endif -%}
{%- endcapture -%}
<title>{{ seo_title | strip }}</title>
您可以只使用以下内容:
{%- unless escaped_page_title contains shop.name or template == 'blog' or template == 'article' -%}
| {{ shop.name }}
{%- endunless -%}
你很接近,但你不能使用括号来分组液体条件运算符。
我通过 theme.liquid 文件中的以下语句将我的品牌名称或商店名称添加到我所有的 URL 中。我想排除所有博客或文章页面。这意味着那些 URL 上没有商店名称,这是管道和代码。
| {{ shop.name }}
原码
{%- capture seo_title -%}
{%- if template == '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>
我一直在尝试围绕以下内容放置另一个 if 语句,但我还没有成功。
{%- assign escaped_page_title = page_title | escape -%}
{%- unless escaped_page_title contains shop.name -%}
| {{ shop.name }}
{%- endunless -%}
这是我试过的代码,有没有更好的方法来实现它,因为我不能完全让它工作。
尝试的代码
{%- capture seo_title -%}
{%- if template == '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 -%}
{%- if (template == "blog" or template == "article") and current_tags contains '_NOINDEX' -%}
{%- assign escaped_page_title = page_title | escape -%}
{%- unless escaped_page_title contains shop.name -%}
{%- endunless -%}
{%- else -%}
{%- assign escaped_page_title = page_title | escape -%}
{%- unless escaped_page_title contains shop.name -%}
| {{ shop.name }}
{%- endunless -%}
{%- endif -%}
{%- endcapture -%}
<title>{{ seo_title | strip }}</title>
您可以只使用以下内容:
{%- unless escaped_page_title contains shop.name or template == 'blog' or template == 'article' -%}
| {{ shop.name }}
{%- endunless -%}
你很接近,但你不能使用括号来分组液体条件运算符。