要爲Facebook創建正確的og:描述我希望文本文章的前200個字符必須用作描述(否則它只是標題)。如果對一個變量的內容進行條件處理(如果包含字符)
所以在我的頭文件中我寫道:
{if not empty($post_info.parsed_excerpt)}
<meta name="description" content="{$post_info.parsed_excerpt|truncate:200|escape}" property="og:description">
{else}
<meta name="description" content="{$post_info.title|escape} - {$blog_data.title|escape}" property="og:description">
{/if}
雖然我說得對,但我發現有例外。 文章可能包含的東西不僅僅是可讀的文字,而且圖像插件也可能存在於此<img src="http.../>
。我甚至有沒有文字內容,只有一個圖像的情況。
所以我需要適應它。 我發現strip_tags修飾符,所以我調整了一下 {$post_info.parsed_excerpt|truncate:200|escape}
到 {$post_info.parsed_excerpt|truncate:200|strip_tags|escape}
和說明現在沒有任何標籤。一半完成!:)
仍然我需要第一個條件{if not empty($post_info.parsed_excerpt)}
尋找$post_info.parsed_excerpt
沒有標籤,我不知道如何。
感謝您幫助
你最好先帶標籤,然後截斷爲200:'{$ post_info.parsed_excerpt |用strip_tags |截斷:200 |逃生}' – m13r
什麼是首要條件?我不明白...只要對其他變量做同樣的事情...... – m13r