cakephp分离元关键字和描述
我有一个用cakephp制作的网站。它有三个层次:首页、章节、文章 我为每个章节和每篇文章分离了元关键字和描述 我把主页的元描述如下cakephp分离元关键字和描述,cakephp,keyword,meta-tags,Cakephp,Keyword,Meta Tags,我有一个用cakephp制作的网站。它有三个层次:首页、章节、文章 我为每个章节和每篇文章分离了元关键字和描述 我把主页的元描述如下 <? if($title_for_layout=="Home"){?> <title><?php echo $this->Session->read('Setting.title');?></title> <? echo $this->Html->meta('keyw
<? if($title_for_layout=="Home"){?>
<title><?php echo $this->Session->read('Setting.title');?></title>
<?
echo $this->Html->meta('keywords', $this->Session->read('Setting.meta_keywords'));
echo $this->Html->meta('description', $this->Session->read('Setting.meta_description'));
?>
<? if($title_for_layout=="Section"){?>
<title><?php echo strip_tags(trim($title_for_layout));?></title>
<?
echo "sawy";
echo $this->Html->meta('keywords', $metaKeywords);
echo $this->Html->meta('description', $metaDescription);
?>
<? } ?>
<? }else{ ?>
<title><?php echo strip_tags(trim($title_for_layout));?></title>
<?
echo $this->Html->meta('keywords', $metaKeywords.' ,'.$article['Section']['meta_keyword'].' ,'.$this->Session->read('Setting.meta_keywords'));
echo $this->Html->meta('description', $metaDescription.' ,'.$article['Section']['meta_description'].' ,'.$this->Session->read('Setting.meta_description'));
?>
<?}?>
我想告诉代码,如果它是一节放它的关键字,如果是一篇文章放它的关键字。
因为它不起作用
这里是URL的示例
domain.com/section/2/programinig
用于Cake 2.x的domain.com/article/9992/learnppp
我不会使用版面的标题来决定必须使用哪些元和关键字
我的建议是使用积木
因此,在您的布局文件中,我可能会在标题中添加一些行,如下所示:
echo$this->Html->meta'keywords',$this->fetch'head_keywords';
echo$this->Html->meta'description',$this->fetch'head_description';
然后,在您的视图文件中,您只需定义这些块,这些文件是特定于主页、节或您需要的任何内容的
例如,在主页视图文件中,您将拥有:
$this->assign'head_description','这是主页的描述';
$this->分配“head_关键字”,“这是主页的关键字”;
您将对剖面视图或文章视图执行相同的操作
蛋糕1.3
CakePHP1.3没有块,因此您必须像这样模拟它
在布局文件中添加以下代码:
if( !isset($head_keywords) ){ $head_keywords = '';} //define if not defined
if( !isset($head_description) ){ $head_description =''; }
echo $this->Html->meta('keywords', $head_keywords );
echo $this->Html->meta('description', $head_description );
然后,在视图文件中,您需要以以下方式添加关键字和元数据:
$head_keywords = 'put here your keywords';
$head_description = 'put here your description';
$this->set( compact( 'head_keywords', 'head_description' ) ); //make these visible in the layout context
在cakephp 2.x中,在布局文件中
<?php
echo $this->Html->meta('keywords', empty($keywords) ? 'Propcampus.com,Property in Noida, Property in Delhi, Property in Gurgaon,Property in India, Property in Lucknow, Property in Gorakhpur, 1 BHK in Noida, 2 BHK in Noida, 3 BHK in Noida, 4BHK in Noida, ' : $keywords);
echo $this->Html->meta('description', empty($description) ? 'Propcampus.com is a online realrestate portal' : $description);
echo $this->Html->meta(array('property' => 'og:title', 'type' => 'meta', 'content' => $this->fetch('title'), 'rel' => null));
echo $this->Html->meta(array('property' => 'og:url', 'type' => 'meta', 'content' => empty($url) ? 'Propcampus.com is a online realrestate portal' : $url, 'rel' => null));
echo $this->Html->meta(array('property' => 'og:description', 'type' => 'meta', 'content' => empty($description) ? 'Propcampus.com is a online realrestate portal' : $description, 'rel' => null));
echo $this->Html->meta(array('property' => 'og:image', 'type' => 'meta', 'content' => empty($imgurl) ? 'Propcampus.com is a online realrestate portal' : $imgurl, 'rel' => null));
echo $this->Html->meta(array('property' => 'og:type', 'type' => 'meta', 'content' => 'website', 'rel' => null));
?>
在您的视图文件中
<?php $this->assign('title', $details['PropertyDetails']['property_type']); ?>
<?php
$description = $details['PropertyDetails']['seo_desc'];
$keywords = $details['PropertyDetails']['seo_keyword'];
$url = Router::url( $this->here, true );
$imgurl = $details['PropertyDetails']['property_image'];
$this->set(compact('keywords','description','url','imgurl')); ?>
我确实尝试过你的想法。但是当我把echo$this->Html->meta'keywords',$this->fetch'head_keywords';echo$this->Html->meta'description',$this->fetch'head_description';它使我的主页无法工作。我的cakephp是1.3OK,我已经用cakephp 1.3thanks LLie的解决方案更新了答案。我按照你说的做了,但我无法从数据库中获取要显示在章节页面上的章节数据。我没有看到来自数据库的变量