Hi friends, I would like to know how to add "Tags" feature for my website just like del.icio.us or any other website. Please help me finding a code or tutorial or a book which can help me adding this feature. waiting for reply.... Thank you very much..... Smart.........
What language specifically? I've written one from scratch, it's a pretty easy concept. Basically on the content that will allow tagging, you give the user an ability to add tags (usually a single text box). On the script that adds the content, you split the tags field using commas. What I do then is insert each tag into a tags table (ID, TagName) ignoring duplicates (the table has a primary get on the tagname, to ignore duplicates using mysql use INSERT IGNORE...). Table Tags (Primary Key on TagName) TagId, TagName I then fetch all the tags by tagname to get their id's. SELECT TagId FROM TABLE WHERE TagName IN (...tags here).. I insert into an additional table all those tag ids with the id of the newly inserted content. Table ContentTags ContentId, TagId, DateAdded Each tag gets it's own row with the content id in this table. So if a piece of content has 10 tags, it gets 10 records, 1 for each tag. Then at any time I can lookup the tags for a piece of content with: SELECT C.*, T.TagName FROM ContentTags WHERE ContentId = 123 To get the actually tag values with it you can join it to the tags table: SELECT * FROM ContentTags C LEFT JOIN Tags T ON C.TagId = T.TagId WHERE ContentId = 123 You can also do things like looking up the count of content by tags for all time, a specific range, today, etc. SELECT TagId, COUNT(*) FROM ContentTags WHERE DateAdded > SOMEDATE GROUP BY TagId This allows you to get Weekly top tags, Monthly, Todays, Yesterday, etc. To display the tags list, you basically select a certain number of tags, say the 100 most popular for today. Then you find out the largest count, say the biggest tag has 50 entries. You then print out all the tags, adjusting their font size based upon the number of entries it has. If the smallest font size is 12px, and the largest you want is 24px, then the size is based upon it's percentage from the largest tag. If the largest tag is 50 entries, that gets 24px, the smallest gets 12px, and you determine the font size for the rest by dividing it's count by the largest count. If you want to roll your own, that's the basic idea, I know their are some samples and libraries available depending on the language. If you're writing this in php, I know of a specific open source library for it, but I can't remember it off hand. Let me know if you want that and I can dig it up.