Welcome Guest, Not a member yet? Register   Sign In
Articles and clean urls
#1

[eluser]Firestorm ZERO[/eluser]
I'm currently working on articles which are stored in a mySQL db and looking at the idea of clean urls.

I'm wondering what is the best way to implement the links for clean urls.

Using url_title($var) to change the article title to produce the clean url so I can have like "test.com/article/name-of-article/".

But to look for it then I think I will have to store the clean url of the title ("name-of-article") in the database or else I will be have to search through the whole DB and convert each title to look for it since I have not passed the unique id (article_id).

I have seen other sites do like "test.com/article/article-id-name-of-article/" or "test.com/article/article-id/name-of-article/"

I believe Wordpress puts the date before the article title. So I guess it limits the search by date first and then looks for the title since the chance of two articles of the same name on the same date would be rare. (But then how does it handle duplicates?)

So what is the best way to implement this?
#2

[eluser]Isern Palaus[/eluser]
Hello Firestorm ZERO,

Probably I don't understand you at all... but when I use url_title($title) I store the "slug" like I store the id and the body of the article. Then, when a user try to access to /article/this-url I search in the DB if there's something equal, if it is, I show.

Another thing to do is to create a function that checks if the url_title already exists on the database and add a -1, -2 depending of the number of url_title's equal on the database.

By the way, add the date on the URI I think that it's only a visual thing Tongue

Sorry for my school English.

Regards,
-- Isern Palaus
#3

[eluser]Firestorm ZERO[/eluser]
I just checked a wordpress db and the url_title version is stored in the DB.

I was just thinking if there was other ways because searching by a string can slow the DB.
#4

[eluser]Isern Palaus[/eluser]
Its not a SELECT * from TABLE LIKE %url_title%, it's a SELECT * from TABLE WHERE slug = 'slug'. ;-)

See you,
-- Isern Palaus




Theme © iAndrew 2016 - Forum software by © MyBB