This an easy solution for adding tag support for any website. This is not a complete script, or addon, just a method you can use easily. The result will produce a tag cloud, like the one you can see in my sidebar.
STEP 1: Setup. Let's assume that you have a site that stores the articles in a table. You have to add a field that will store the tags. The tags will be separated by a space character.
STEP 2: Generating the tag list:
function get()
{
// CodeIgniter based database query.
$this->db->select( 'p_tags');
$this->db->from( 'posts' );
$query = $this->db->get('posts');
/**
* If the loop on the tags founds a tag that is already
* represented in the $tag_cloud array as a key, then
* its value will be inceremented by 1
*/
$tag_cloud = array();
foreach ( $query->result_array() as $key => $t )
{
$tags = $t['p_tags'];
if( $tags )
{
// Tags must be separated by 'space'
$tags = explode( ' ', $tags );
foreach( $tags as $tg )
{
if( !array_key_exists( $tg, $tag_cloud ) )
{
$tag_cloud[ $tg ] = 1; // Default count
}
else
{
$tag_cloud[ $tg ]++; // Tag exists, increment its value
}
}
}
}
// Order by value, keep indexing, reverse order
arsort( $tag_cloud );
return $tag_cloud;
}
$this->db->where( "p_tags LIKE '% $cat %' OR p_tags LIKE '$cat %' OR p_tags LIKE '% $cat' p_tags = '$cat'" );Note that the first and third rule has only one %.
All rights reserved, ©2008-2010 - Built on CodeIgniter framework - Konami codes - Mostly Valid XHTML 1.1 - Valid CSS 2.1