slug

Better to save a slug to the DB or generate dynamically?

非 Y 不嫁゛ 提交于 2019-12-06 03:33:17
问题 I am working on a django project and would like to include a slug at the end of the url, as is done here on stackoverflow.com: http://example.com/object/1/my-slug-generated-from-my-title The object ID will be used to look up the item, not the slug -- and, like stackoverflow.com, the slug won't matter at all when getting the link (just in displaying it). Qestion : is there a downside (or upside) to generating the slug dynamically, rather than saving it as an actual database field ? For example

Wordpress multiple slugs for a Custom Post Type

南笙酒味 提交于 2019-12-06 03:18:15
A custom post type can be registered with one slug (e.g. products) register_post_type('products', $args); How can I add multiple slugs to the same Custom Post Type? website_address.com/en/products/ website_address.com/fr/produits/ website_address.com/it/prodotti/ henrywright The rewrite argument for register_post_type() accepts an array. One of the array keys is slug . So you could i18n it like this: register_post_type( 'products', array ( 'rewrite' => array ( 'slug' => _x( 'products', 'URL slug', 'your_text_domain' ) ) ) ); Idea taken from here . Ref: https://codex.wordpress.org/Function

Make a post slug unique

大兔子大兔子 提交于 2019-12-06 01:41:49
问题 I got few functions in placed which is not working as I wanted. The slug is automicatlly created on the fly depend on the post title. Example: If a post title is "test" then the slug will be "test" My problem is that, what if theirs duplicate entry of post title "test" which means that the slug will be duplicated too. For that reason I have create 2 functions to handle this for me. This function checks if the slug exist in the database function slug_exist($x){ global $db; $sql = "SELECT post

creating unique page title slugs php

大城市里の小女人 提交于 2019-12-06 00:06:07
问题 I have a function for creating unique slug for a page title. It checks if the slug is available in the pages table then creates a unique slug by adding a '-int' accordingly. The function works fine for the first three entries eg for 'test slug' entered three time will create 'test-slug-1', 'test-slug-2' and 'test-slug-3'. Then after that I get an error "Fatal error: Maximum execution time of 30 seconds exceeded" for the fourth entry. There should be some problem with the logic, can anyone

slug field on flask

感情迁移 提交于 2019-12-05 13:37:49
I want to create a slug field stored in database. I searched and I found http://flask.pocoo.org/snippets/5/ but I'm having trouble integrating the code in my app. This is my modele.py : from unicodedata import normalize def slugfy(text, encoding=None, permitted_chars='abcdefghijklmnopqrstuvwxyz0123456789-'): if isinstance(text, str): text = text.decode(encoding or 'ascii') clean_text = text.strip().replace(' ', '-').lower() while '--' in clean_text: clean_text = clean_text.replace('--', '-') ascii_text = normalize('NFKD', clean_text).encode('ascii', 'ignore') strict_text = map(lambda x: x if x

How to Set POST permalink/slug in wordpress using wp_insert_post

牧云@^-^@ 提交于 2019-12-04 19:19:42
问题 I m writing simple script using wp_insert_post() to post article in blog. but one problem here, I want to make Title and slug of an URL different. How to achieve this? for example: Title: How to make your diet success Slug: 7-ways-to-make-succes-Diet 回答1: post_title sets the title, and post_name sets the slug. So: // Create post object $my_post = array( 'post_title' => 'How to make your diet success', 'post_name' => '7-ways-to-make-succes-Diet', 'post_content' => 'my content', 'post_status' =

Best way to create SEO friendly URI string

[亡魂溺海] 提交于 2019-12-04 19:17:38
问题 The method should allows only " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- " chars in URI strings. What is the best way to make nice SEO URI string? 回答1: This is what the general consensus is: Lowercase the string. string = string.toLowerCase(); Normalize all characters and get rid of all diacritical marks (so that e.g. é, ö, à becomes e, o, a). string = Normalizer.normalize(string, Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); Replace all remaining non

Incrementing the slug by avoiding Integrity error in django models save method

删除回忆录丶 提交于 2019-12-04 15:14:25
I have a model with two fields as below models.py class Publisher(models.Model): name = models.CharField(max_length=200) slug = models.SlugField(max_length=150, unique=True) def save(self, *args, **kwargs): if not self.id and not self.slug: slug = slugify(self.name) try: slug_exits = Publisher.objects.get(slug=slug) if slug_exits: self.slug = slug + '_1' except Publisher.DoesNotExist: self.slug = slug super(Publisher, self).save(*args, **kwargs) Here i am creating a slug based on the name field as we can see above So when we try to create a publisher with name already exists , the save method

create URL slugs for chinese characters. Using PHP

心已入冬 提交于 2019-12-04 13:53:25
问题 My users sometimes use chinese characters for the title of their input. My slugs are in the format of /stories/:id-:name where an example could be /stories/1-i-love-php . How do I allow chinese characters? I have googled and found the japanese version of this answer over here. Don't quite understand Japanese, so I am asking about the chinese version. Thank you. 回答1: i have tested in Bengali characters it may work. try this: at first the coded page (write code where in the page) have to

Slug Url Regex in Django

戏子无情 提交于 2019-12-04 11:35:29
问题 After reading a lot about proper use of a slug to create a detail view from a list of objects. However, I am still having problems getting it to work for me. I am displaying a list of objects in my template like: {% for thing in thing_list %} <div class='thing-detail'><a href='{% url detail %}'><img src='theimage.png' /> {% endfor %} But am getting a NoReverseMatch error on detail . I figure that there is either something wrong with my regex, or there is just a better way of doing this that I