3

在 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"/>
4

3 回答 3

2

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

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

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

<?php echo $this->Html->meta(array('name' => 'og:type', 'content' => 'discussion'), NULL, array('inline' => false)); ?>
于 2013-02-27T12:35:41.607 回答
2

可以通过将一些特定选项传递给帮助程序来创建具有property属性而不是属性的元标记:namemeta

$this->Html->meta(array('property' => 'og:title', 'type' => 'meta', 'content' => 'My brilliant page', 'rel' => null));
于 2014-10-07T11:33:21.077 回答
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"/>
于 2016-06-05T01:50:35.927 回答