سؤال

I've just created a draft on my blog, and it's post ID is 1. After creating another draft, the post id for this last post is 3! I was hoping to see them in sequential order, so in the future I'll have a nice auto-incremented numbering like

../archives/1  
../archives/2   

some months later...

../archives/154
../archives/155

I have no problem diving into code, but I was wondering if someone happens to know a simple solution to achieve this.

Thank you.

هل كانت مفيدة؟

المحلول

The ID of a post is not meant to be a sequence number in the sense that for post N the following post is N+1. The ID is an auto-incremented field in the posts table, which includes many things that are not published posts, e.g., drafts, pages, attachments. So there is really no way to force WordPress to assign sequential IDs in that field.

There are ways to produce a sequence number and then use it in the permalink structure, but any efficient system will involve storing the IDs in a separate location (table or option) and writing a custom rewrite plugin. That last bit is quite advanced.

It would be an intriguing problem for the experienced hacker to produce a plugin that solves this problem without significant performance degradation.

نصائح أخرى

Pages and posts share ID's so I doubt that will work

Also - The best permalink structure for SEO is to include the postname in there

As the others have explained, the post ID is an auto-incremented field in the database, and so is not otherwise controllable. You obviously don't want to use this in your permalink.

Plugins and custom fields are an option, but not recommended because any "naked" number has the possibility of being misinterpreted by WordPress as a post ID or other internal number like year or date.

A simpler solution that doesn't require custom fields or plugins is to edit the post slug for each post and give it a sequential number preceded by a constant alphabetical prefix.

For example, instead of:

../archives/1  
../archives/2 
...
../archives/x

use:

../archives/p1  
../archives/p2 
...
../archives/px

Changing your permalink structure, you could even shorten this to:

../p1  
../p2 
...
../px

You can replace the "p" with whatever you want, like "day1" or "deep-thought-1".

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى wordpress.stackexchange
scroll top