Coder Social home page Coder Social logo

cakephp-plugin-seo's Introduction

/*
 * SEO CakePHP Component
 * Copyright (c) 2008 Matt Curry
 * www.PseudoCoder.com
 * http://github.com/mcurry/seo
 *
 * @author      Matt Curry <[email protected]>
 * @license     MIT
 *
 */

/* About */
	The intent of this component is to automatically set relevent page titles and meta descriptions
based on the content being sent to the view.  It also assists in make pretty urls.

/* Notes */
  * This component is in a very early state.  It probably won't work automatically in your application.
  * Patches for supporting a larger application base are appreciated.

/* Instructions */
  1. Include the component in your app controller:
    var $components = array('Seo.Seo');
  
  2. The component will automatically try to pull relevant information for the title/meta description from:
    a. $Controller->data
    b. $Controller->viewVars
    
  3. In your view the meta description is assigned to $meta_description_for_layout.
  
  4. The page title will be $title_for_layout (CakePHP standard);
  
  5. There is also a 2nd class "Seo" which has a static function for creating pretty urls.
     Say you were making a link to view a blog post and you wanted the link to be
     "/posts/view/12/this-is-the-blog-post-title" you would create the link:
     $html->link($post['Post']['name'], array('action' => 'view', Seo::slug($post['Post'])));
     The url function will automatically pull the id and title from $post and create the link.
  
  6. In your controller you can leave the view function as is "function view($id) { ... }".
     CakePHP will automatically populate the $id and ignore the extra title param.
		 
	7. If you are worried about slug consitency you can use the verifySlug which will force a 301 redirect if the slug doesn't match.
		function view($id, $slug=null) {			
			$post = $this->Post->read(null, $id);
			$this->Seo->verifySlug($post);			
			$this->set('post', $post);
		}
	
/* Short Urls */
	If you need to post a link on twitter or some other service with limited characters simply remove the slug part of the link.
	For example: "/posts/view/12/this-is-the-blog-post-title" to "/posts/view/12"
	
/* Even Shorter Urls */
	Since the component works with Cake's built in routing system you can add a route like:
	Router::connect('/p/*', array('controller' => 'posts', 'action' => 'view'));
	All your links will be generated as: "/p/12/this-is-the-blog-post-title" and you can use "/p/12" as a short link

cakephp-plugin-seo's People

Contributors

mcurry avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.