【问题标题】:How to dynamically set open graph meta tags in zend for facebook sharing如何在 zend 中动态设置开放图元标记以进行 facebook 共享
【发布时间】:2016-02-03 19:29:49
【问题描述】:

我想动态设置开放图元标记,以便可以从控制器或视图中完成。我尝试了很多我在搜索过程中得到的东西,但没有成功。以下是我已经尝试过的解决方案:

我在 Module.php 的 onBootstrap 方法中写了以下几行

    $doctypeHelper = new Doctype();
    $doctypeHelper->setDoctype('XHTML1_RDFA');

然后在视图的 index.phtml 中,我尝试通过编写以下代码行来设置描述元标记。

    <script>
    <?php echo $this->doctype('XHTML1_RDFA'); ?>
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:og="http://opengraphprotocol.org/schema/">
    <head>
    <meta property="og:description" content="musician" />
    </script>

我也尝试过这个解决方案,我在控制器中编写了以下代码行。

    $renderer = $this->getServiceLocator()->get('Zend\View\Renderer\PhpRenderer');  
    $renderer->headMeta()->appendName('og:description', 'pimcore is great'); 

有什么方法可以动态设置开放图元标记?我必须设置这些元标记“og:url”、“og:title”、“og:image”、“og:description”。

【问题讨论】:

    标签: php facebook zend-framework zend-framework2 og-meta


    【解决方案1】:

    HeadMeta 助手http://framework.zend.com/manual/current/en/modules/zend.view.helpers.head-meta.html

    肯定会奏效。看看该页面上的最后一个示例:

    $this->doctype(Zend\View\Helper\Doctype::XHTML1_RDFA);
    $this->headMeta()->setProperty('og:title', 'my article title');
    $this->headMeta()->setProperty('og:type', 'article');
    

    【讨论】:

      猜你喜欢
      • 2012-07-21
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 2016-05-30
      • 1970-01-01
      • 2019-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多