【问题标题】:How to use current URL as Href in facebook comments?如何在 facebook 评论中使用当前 URL 作为 Href?
【发布时间】:2018-07-15 03:51:04
【问题描述】:

我正在使用 facebook cmets 插件,我相信我在使用它时没有设置 href,它会自动使用当前 url 作为 href 但它停止工作说我必须设置 href。

如何将 HREF 设置为当前 URL,以便在每个页面上获得不同的 cmets?

<fb:comments href="" num_posts="2" width="500" style="padding-top: 20px; margin-top: 20px; border-top: 1px dotted grey;"></fb:comments>

谢谢

【问题讨论】:

    标签: php facebook


    【解决方案1】:

    如果您使用的是 wordpress(我的猜测),您应该在 fb:comments 中输入 &lt;?php the_permalink(); ?&gt;

    <fb:comments href="<?php the_permalink(); ?>" num_posts="2" width="500" style="padding-top: 20px; margin-top: 20px; border-top: 1px dotted grey;"></fb:comments>
    

    如果不尝试制作网址

    $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https'; // get the protocol
    $host = $_SERVER['HTTP_HOST']; // host name
    $script = $_SERVER['SCRIPT_NAME']; // script path
    $params = $_SERVER['QUERY_STRING']; // params
    $uri = $_SERVER['REQUEST_URI']; // full script path with params if you are not interested in protocol or host name
    

    所以

    $currentUrl = $protocol . '://' . $host . $script . '?' . $params;
    // or
    $currentUrl = $protocol . '://' . $host . $uri;
    
    <fb:comments href="<?php echo $currentUrl; ?>" num_posts="2" width="500" style="padding-top: 20px; margin-top: 20px; border-top: 1px dotted grey;"></fb:comments>
    

    【讨论】:

      猜你喜欢
      • 2012-01-15
      • 2012-02-01
      • 2013-06-06
      • 2011-11-04
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 2014-11-04
      相关资源
      最近更新 更多