首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >纯数字wordpress固定链接

纯数字wordpress固定链接
EN

Stack Overflow用户
提问于 2011-11-04 18:28:17
回答 3查看 1.2K关注 0票数 2

我可以有一个数字的wordpress固定链接吗?尝试强制永久链接为"2“,例如自动将其重写为"2-2”。

进一步研究一下,我发现这是任何数字固定链接的情况-我认为它与可能的分页干扰有关,但有一个我想要使用此结构的用例。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-11-05 11:18:55

我已经处理过一次,通过截取post插件创建并以某种方式“修复”它。也许你可以这样做:

代码语言:javascript
运行
复制
 /*
 * 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过滤器可能就是不错的选择。

票数 0
EN

Stack Overflow用户

发布于 2012-08-23 22:50:19

实际上,这可以从设置中的固定链接部分轻松完成。您只需将/post_id/设置为固定链接结构,它就会工作得很好。

票数 1
EN

Stack Overflow用户

发布于 2011-11-05 01:53:01

您可能已经有一个带有slug‘2’的帖子;如果它不在帖子管理面板中,那么它可能还在垃圾桶中。

另外,使用数字作为slug可能不是最好的主意--它可能会与分页和其他重写规则冲突,并且可能无法描述该帖子的用途。

希望这能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8007881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档