Reputation: 1
I have website made with cakephp . it has 3 levels Home,sections,articles I have separated meta keywords & description for every section & every article.
I put meta description for home page like this
<? 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'));
?>
<?}?>
I want tell code if it be section put its keywords & if be article put its keywords. because it not work here example of urls
domain.com/section/2/programinig domain.com/article/9992/learnphp
Upvotes: 0
Views: 2773
Reputation: 174
In cakephp 2.x, In your layout file
<?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));
?>
In your view file
<?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')); ?>
Upvotes: 1
Reputation: 1839
For Cake 2.x
I would not use the title of the layout to decide what meta and keywords must be used.
My recommendation would be to use blocks
See documentation.
So in your layout file (probably default.ctp
) I would put in the header some lines like this:
echo $this->Html->meta('keywords', $this->fetch( 'head_keywords' ) );
echo $this->Html->meta('description', $this->fetch( 'head_description' ) );
Then in your view files that are specific for Home page, or section or whatever you need, you will simply define those blocks.
For example in the home page view file you will have:
$this->assign( 'head_description', 'this is the description for the home page' );
$this->assign( 'head_keywords', 'this are the keywords for the home page' );
You will do the same for your section views or article views.
For Cake 1.3
CakePHP 1.3 does not have blocks so you will have to emulate it like this.
In your layout file add this code:
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 );
Then in your View files you need to add your keywords and metadata in this fashion:
$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
Upvotes: 9