代码之家  ›  专栏  ›  技术社区  ›  talkinggoat

Joomla:将文章图片放在脸书的头部

  •  1
  • talkinggoat  · 技术社区  · 7 年前

    我想提取这篇文章的简介图片,并将其插入Facebook的og:图片元数据的头部。问题是,我似乎无法得到正确的信息来填写。这是我试过的。。。

    <?php echo '<meta property="og:image" content="'.$images->image_fulltext.'">';
    ?>
    
    <?php echo '<meta property="og:image" content="'.JLayoutHelper::render('joomla.content.intro_image', $this->item).'">';
    ?>
    

    还尝试了:

    $doc = JFactory::getDocument();
    $images = json_decode($this->item->images);
    $fbimage = JURI::base() . $images->image_fulltext;
    $doc->addCustomTag( '<meta property="og:image" content="' . $fbimage . '">' );
    

    我所能做的就是 <meta property="og:image" content="">

    我需要什么来获取文章图像或简介图像的FQDN?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Irfan    7 年前

    您可以尝试以下代码-

    $doc = JFactory::getDocument();
    $doc->addCustomTag('<meta property="og:image" content="'. Juri::root() . $images->image_fulltext .'">');
    

    Juri::root() 返回网站URL。有关的更多详细信息 Juri Class

    为了获得简介图像或完整图像路径,您可以参考 this link