如何在每个帖子中实现og:tag?

时间:2013-02-27 11:50:24

标签: cakephp

在我的developer.ctp文件中的cakephp项目中,我实现了og:tags。我已经完成了四种类型的这种。当我添加一个新帖子时,那时我想实现每个帖子应该有这样的og标签:

<meta property="og:type" content="discussion" />
<meta property="og:url" content="URL" />
<meta property="og:title" content="any title" />
<meta property="og:image" content="any comment"/>

3 个答案:

答案 0 :(得分:2)

要显示元标记,请将其放在default.ctp布局的标题中:

<?php echo $this->fetch('meta'); ?>

为您希望它们显示的视图中的每个元标记放置类似的内容:

<?php echo $this->Html->meta(array('name' => 'og:type', 'content' => 'discussion'), NULL, array('inline' => false)); ?>

答案 1 :(得分:2)

通过将一些特定选项传递给property帮助程序,可以创建具有name属性而非meta属性的元标记:

$this->Html->meta(array('property' => 'og:title', 'type' => 'meta', 'content' => 'My brilliant page', 'rel' => null));

答案 2 :(得分:2)

在Cakephp 3.x中,你可以简单地使用这个

$this->Html->meta(null, null, [
    'property' => 'og:title',
    'content' => 'this is an article title',
    'block' => 'meta']);

结果

<meta property="og:title" content="this is an article title"/>