Like an "un-slug" header header

I am creating a system that requires a slug system. For example, the URL for a blog post called “Blog Title: Here” would look like this:

YYYY / MM / DD / -blog-title here

My system is very well configured, where if your URL matches more than one entry, it displays a summary of all matching entries, and if it matches only one entry, it displays the complete entry and so on. The only problem I am facing is the "disconnection" of the name. Currently, I only consider the first word: my SQL query ends as follows:

'AND subject LIKE '.$this->db->escape(substr($title,0,strpos($title,'-')).'%')

The problem is that if two posts published on the same day begin with the same word, a single post can never be matched. In addition, if one message begins with the word “A,” and another message sent on the same day starts with the letter A, the previous post can never be matched alone.

My initial thought was to try to combine every word in slug with LIKE %word%, and although it is better, it seems hacky and still not perfect (“Slug: troublesome!” And “Problem slug” will conflict). Is there an elegant solution to this problem?

+3
source share
1 answer

"slug" ? , , URL- . . slug , , , . , "my-post", "my-post-1".

, , .

+6

Source: https://habr.com/ru/post/1764237/


All Articles