2011-11-04 134 views
2

我可以有单数字wordpress永久链接?试图强制永久链接为“2”,例如自动将其重写为“2-2”。纯数字wordpress永久链接

寻找到它远一点,我发现这是任何数值固定链接的情况下 - 我认为它具有与寻呼可能的干扰做,但有一个使用情况下,我想用这个结构..

回答

0

我已经通过拦截后slu创建并以某种方式“固定”它来处理过这一次。也许你可以这样工作:

/* 
* 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); 

你真的需要一位数的slu?吗?如果您可以使用00001或000005,wp_insert_post_data过滤器可能是您的选择。

+0

谢谢,我会朝这个方向看。这个问题显然比我想象的更麻烦。 – Millions

0

你可能已经有了一个'2'的职位;如果它不在后管理小组中,它可能仍然在垃圾箱中。

在旁注中,使用数字作为slu might可能不是最好的主意 - 它可能与分页和其他重写规则相冲突,并且可能不会描述该帖子的用途。

希望这会有所帮助!

+0

谢谢 - 虽然情况并非如此 - 我认为它与可能的分页干扰有关,但Wordpress不会允许您仅使用数字唯一的固定链接。我有一个特殊的用例,这将是有益的... – Millions

1

实际上,这可以很容易地从设置中的固定链接部分完成。你可以简单地设置/ post_id /作为永久链接结构,它会正常工作。