Creating a tag system for blogs

Discussion in 'Web Design and Development' started by iMasterWeb, Nov 2, 2009.

  1. iMasterWeb macrumors regular

    Joined:
    Mar 15, 2009
    #1
    Hi! Many sites use tags for categorizing posts to provide easy access to posts of a specific subject. So my question is: How do you go about creating one of these?

    Do you create a different page for each "tag" and then list all posts tagged by that tag there? Or is there an easier way? Thanks for any help, and no I'm not using wordpress, I'm doing this by hand.

    -iMaster
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    It's just another table in a database, then there's a table that links a blog entry with a tag.

    Code:
    CREATE TABLE tags (
      id INT PRIMARY KEY NOT NULL,
      name VARCHAR(32)
    );
    CREATE TABLE blog_tag (
     blog_id INT NOT NULL,
     tag_id INT NOT NULL
    );
     
  3. iMasterWeb thread starter macrumors regular

    Joined:
    Mar 15, 2009
    #3
    Is there an in-depth step-by-step tutorial on how to do this somewhere? I'm at a lost when it comes to DB's and MySql and then implementing them in HTML.
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    There's various tutorials you can via your friendly neighborhood search engine. Here's one example for building a blog from scratch, though it doesn't give all the code. I don't have any particular tutorial to point to as none ever cover everything such as security along with the needed markup and database interactions.
     
  5. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #5
    As the OP mentioned they're lost when it comes to PHP/MySQL so I suggest in this situation an alternate approach to consider:

    PHP, XML to store the blog data via a free weblog service, Blogger.

    Read here for a way to integrate Blogger, PHP and XML including generating RSS feeds by simply downloading a few PHP files and using the tutorial which is very easy to follow.

    Not familar with XML? Read here to get the basics (tutorial courtesy of W3 Schools, excellent), it's very easy to learn as it is based on HTML.

    Note: I feel the OP needs to know, for the record, that in the long term learning MySQL and PHP and basic security issues such as SQL injection prevention *is* best, if you can afford the time to do so. Databases allow the kind of flexibility in design that XML does not offer when/if you delve into more complex projects.

    -jim
     
  6. savar macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #6
    Then this might be over your head. Why not use an existing blog program that handles tags for you??
     
  7. iMasterWeb thread starter macrumors regular

    Joined:
    Mar 15, 2009
    #7
    Thanks guys! The basic consensus seems to be that I have to options (basically):

    Learn PHP or choose a CMS (such as Wordpress or Blogger)

    Well I chose the first option because I like the ability to say "This is my site and I built it from scratch!" I also have tons of time. I read some tutorials on W3schools about PHP and MySQL. I now understand a LOT more of the stuff I'm reading on the internet. It also helps with other things I wanted to do like comments, user login, etc. I really appreciate the help and advice!

    -iMaster
     
  8. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #8
    A final comment from me:

    It's great you're motivated to learn PHP and even MySQL or XML along with it. Nothing wrong with that. However, don't feel you must code it from scratch to learn, and they don't give out medals for such things. I'll even suggest you'll learn faster by using a third party product and modifying it and examining code to learn how to do it right from the get go.

    The only major difference between what you would do the first time out and what they have done is how they handle database calls. They create a database abstraction layer so the PHP for MySQL code is maintained independently of PHP used for other stuff. Meaning, novices learning PHP/MySQL will not be creating classes or object oriented programming in most situations. Yet it's good to be exposed to it, even when learning. Be sure to read basic tutorials like this one, as well, so you have a foundation to build on.

    I informally advise at least download some of the open source stuff too that's out there and browse the code to learn best practices and security issues as well even if in the end you create from scratch. I'm just saying starting with someone else's framework is smart - this is an open source community, so take advantage of it. My .02!

    -jim
     
  9. iMasterWeb thread starter macrumors regular

    Joined:
    Mar 15, 2009
    #9
    Definitely! In fact, the provided link is right where I started. But there is NO WAY I'll be able to do this from scratch and Google will be my best friend. I really appreciate your advice! :D
     

Share This Page