1
I created a blog and want to replace part of the URL, when an article is opened, by the title of the article.
http://www.meusite.com/blog/a.php?a=3&v=0
I want to replace the part a.php?a=3&v=0
by title, would be
1
I created a blog and want to replace part of the URL, when an article is opened, by the title of the article.
http://www.meusite.com/blog/a.php?a=3&v=0
I want to replace the part a.php?a=3&v=0
by title, would be
0
The system you want is called slug
.
To work with Slug, it’s easy, but depends on some settings, such as URL amigável
.
In this example, I am creating a function that gets the title of the article and converts to Slug
<?php
function slug($title){
$slug = preg_replace('/[^A-Za-z0-9-]+/', '-', $title);
return $slug;
}
echo slug('O mundo vai acabar em 2016'); //O-mundo-vai-acabar-em-2016'
?>
The function is very basic, other functions can be added: strtolower
or improve the pattern
to avoid special characters.
The function must be used in the link, which will call the page. I recommend that you add before Slug, a parameter for the ID
, as "site.com.br/1293/o-mundo-vai-acabar-em-2016
The url will be theoretically clean for both the search platforms and the end user.
Unless you use the parameter ID
before Slug, you should have some attention
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
vc ta using wordpress?
– Israel Zebulon
try to rename the file containing the page from "a" to my test-article , and instead of making a call GET Voce has to do POST
– Um Programador
I’m not using wordpress, I blogged with PHP.. this page a.php is called when clicking on an article, I could not see the name change to the article name.
– RRV