简体   繁体   English

使用帖子缩略图将动态帖子链接添加到 Facebook

[英]Add Dynamic Post Link To Facebook With Post Thumbnail

I'm using this code from the official FB Developer page我正在使用来自官方FB 开发者页面的代码

<div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button_count" data-size="small"><a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&amp;src=sdkpreparse" class="fb-xfbml-parse-ignore">Share</a></div>

But it's hard coded 1 URL.但它是硬编码的 1 URL。 I need to add get_permalink() for the post URL and get_the_post_thumbnail_url() for the featured image but not sure how to do this in PHP.我需要为帖子 URL 添加 get_permalink( get_the_post_thumbnail_url()并为特色图片添加get_permalink()但不确定如何在 PHP 中执行此操作。

I can work out the data-href using get_permalink() but can't get the post thumbnail working.我可以使用get_permalink()data-href ,但无法使帖子缩略图正常工作。

I did output the ig tabs within the head tags like this我做了 output 像这样的头部标签中的 ig 标签

printf( '<meta property="og:url" content="%s" />', get_permalink() );

printf( '<meta property="og:image" content="%s" />', get_the_post_thumbnail_url( get_the_ID(), 'full' ) );

When i use this code it works but it doesn't include the image当我使用此代码时,它可以工作,但不包含图像

'<div class="fb-share-button" data-layout="button_count" data-size="large"></div>';

Is there a way to add the single post URL and featured image in PHP using sprintf?有没有办法使用 sprintf 在 PHP 中添加单个帖子 URL 和特色图像?

Works, the only problem was when using local it doesn't.工作,唯一的问题是使用本地时它没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM