我的目標是如果我的帖子在分享時包含特定的class/es
,則需要進行特定的圖片預覽。如何根據div類分配元標記圖像內容url值?
我正在使用博客平臺及其默認代碼。
<b:if cond='data:post.labels any (l => l.name in {"video", "youtube"})'>
<meta content='post-with-video-class.jpg' property='og:image'/>
<b:elseif cond='data:post.labels any (l => l.name in {"gallery"})'/>
<meta content='post-with-gallery-class.jpg' property='og:image'/>
<b:else/>
<meta content='default-class-url.jpg' property='og:image'/>
</b:if>
...和我的內容
<div id='posts'>
<div class='video and youtube'>
post 1
</div>
<div class='gallery'>
post 2
</div>
<div class='default'>
post 3
</div>
</div>
如果是body
內,纔能有預覽圖像此代碼只會工作,meta
標籤應該是裏面head
。
我試圖追加jQuery,但仍然沒有預覽圖像。
$("[property*='og:image']").appendTo ("head");
是否有任何jQuery代碼來代替博客的代碼? 我正在閱讀classList
和hasClass
,但執行它們仍然離我的知識還很遙遠。請幫忙。
如果您要將這些標籤用於Facebook或任何其他社交媒體平臺,它將無法正常工作,因爲需要在加載頁面時創建元標記 –
我有兩個問題:您是否想擁有爲帖子列表網頁或帖子詳細信息網頁設置的「og:image」?你使用哪個主題? –
@winner_joiner我希望他們在兩種頁面類型。它從頭開始。 – 88willr