Cách tạo thẻ OG:IMAGE cho bài viết XenForo 2
Bài viết này sẽ hướng dẫn các bạn cách tạo thẻ og:image thông minh bằng cách tìm tập tin trong bài viết và tự động lựa chọn tập tin hình ảnh có kích thước lớn nhất làm thẻ og:image. Cách làm như sau:
Mở template thread_view, tìm đoạn code sau:
Thay bằng:
Lưu lại là xong.
Chúc các bạn thành công.
Bài viết này sẽ hướng dẫn các bạn cách tạo thẻ og:image thông minh bằng cách tìm tập tin trong bài viết và tự động lựa chọn tập tin hình ảnh có kích thước lớn nhất làm thẻ og:image. Cách làm như sau:
Mở template thread_view, tìm đoạn code sau:
Mã:
<xf:macro template="metadata_macros" name="metadata"
arg-description="{$fpSnippet}"
arg-shareUrl="{{ link('canonical:threads', $thread) }}"
arg-canonicalUrl="{{ link('canonical:threads', $thread, {'page': $page}) }}" />
Thay bằng:
Mã:
<xf:set var="$og_image" value="0" />
<xf:set var="$file_size" value="0" />
<xf:foreach loop="$thread.FirstPost.Attachments" value="$attach">
<xf:if is="$attach.thumbnail_url && ($attach.file_size > $file_size)">
<xf:set var="$og_image" value="{{ link('canonical:attachments', $attach) }}" />
<xf:set var="$file_size" value="{$attach.file_size}" />
</xf:if>
</xf:foreach>
<xf:if is="$og_image">
<xf:macro template="metadata_macros" name="metadata"
arg-imageUrl="{$og_image}"
arg-description="{$fpSnippet}"
arg-shareUrl="{{ link('canonical:threads', $thread) }}"
arg-canonicalUrl="{{ link('canonical:threads', $thread, {'page': $page}) }}" />
<xf:else/>
<xf:macro template="metadata_macros" name="metadata"
arg-description="{$fpSnippet}"
arg-shareUrl="{{ link('canonical:threads', $thread) }}"
arg-canonicalUrl="{{ link('canonical:threads', $thread, {'page': $page}) }}" />
</xf:if>
Lưu lại là xong.
Chúc các bạn thành công.
Nguồn: hoangnhanpro
Bài viết liên quan
Bài viết mới