Basic SEO and CakePHP (part 1)
(in English, for a change)
Pretty URLs
CakePHP easily produces URLS as http://www.mysite.com/post/view/456. Not too bad. But using the title of the post in the URL can slightly improve the relevancy of the link as seen by Google or other robots. For this, simply use the “Sluggable” Behaviours from Mariano Iglesias. It’s here. It helps generating string as “my-post-about-sea-and-shells” from the fields you want in your model. Very handy. A little bit of route tickering and you’ll have URLs such as http://www.mysite.com/post/view/my-post-about-sea-and-shells/
quick tip : if you want your content to appear in Google News, the URLs of each post must include a three digit number. So you’d better leave the id as it is (and even pad it with extra zeros).
keywords and description
Yes, these are basic concerns: it’s better if each page has its own keywords and description. It may be overlooked by some, but the Google Webmaster Tools will still consider it as a flaw if many of your pages share the same description sentence. As to keywords, they are not taken into account by most robots, but they may be used by some links directories. In CakePHP, the layout (where HTML headers and the keywords and description tags are) is shared between pages (or at least sections, depending on your design), and we can’t imagine changing layout on a per-page basis… There’s one obvious function in the HtmlHelper that can be used to add metatags to your page. Here is how:
The last parameter indicates whether you want the generated code to appear inline or between the head tags where you have echoed the $scripts_for_layout var. By digging into the source code, I found that the method addScript from the view class is used to achieve that, using the $scripts_for_layout variable. So it can be used directly, but to me the meta method is the obvious choice (so obvious it’s not even documented for the moment in the CakePHP documentation).
title
The title of the page is very important. Setting it on a per-page basis in CakePHP is easy. You just have to set it in your action (”view” or “index”) using data from the model. The variable to set is “pageTitle”.
-
$this->pageTitle = $post[‘Post’][‘title’];
(to be continued… feel free to ad tips in the comments, of course!)
Cécile said,
mars 16, 2008 @ 11:56
Wow, dear, that’s very interesting!