【发布时间】:2011-11-04 10:28:16
【问题描述】:
我可以有单个数字的 wordpress 永久链接吗?试图将永久链接强制为“2”,例如自动将其重写为“2-2”。
进一步研究后,我发现任何数字永久链接都是这种情况——我认为这与可能干扰分页有关,但有一个我想使用这种结构的用例..
【问题讨论】:
标签: wordpress permalinks
我可以有单个数字的 wordpress 永久链接吗?试图将永久链接强制为“2”,例如自动将其重写为“2-2”。
进一步研究后,我发现任何数字永久链接都是这种情况——我认为这与可能干扰分页有关,但有一个我想使用这种结构的用例..
【问题讨论】:
标签: wordpress permalinks
实际上,这可以从设置中的永久链接部分轻松完成。您可以简单地将 /post_id/ 设置为永久链接结构,它会正常工作。
【讨论】:
我曾经通过拦截后期 slug 创建并以某种方式“修复”它来处理过这个问题。也许你可以从这里开始工作:
/*
* New permalink structure
*
* Itercepts every wp_insert_post data to change the regular slugs to md5 hashes
* based on the Unix timestamp of action. This generates a new slug at every
* saving action, which protects the posts against unauthorised direct access.
*
*/
function rm_cpt_permalink_change($data) {
if ($data['post_type'] == 'custom_post_type') {
$time = time();
$data['post_name'] = md5($time);
return $data;
} else {
return $data;
}
}
add_filter('wp_insert_post_data','rm_cpt_permalink_change',10,2);
你真的需要个位数的蛞蝓吗?如果您可以使用 00001 或 000005,wp_insert_post_data 过滤器可能是您的最佳选择。
【讨论】:
您可能已经有一个带有 slug '2' 的帖子;如果它不在帖子管理面板中,它可能仍在垃圾箱中。
附带说明,使用数字作为 slug 可能不是最好的主意 - 它可能与分页和其他重写规则冲突,并且可能无法描述该帖子的用途。
希望这会有所帮助!
【讨论】: