簡體   English   中英

永久鏈接更改wordpress中的每個帖子更新

[英]Permalink change each post update in wordpress

我想為WordPress中的每個新帖子提供一個自定義的永久鏈接,例如: http : //mysite.com/x5Kvy6

function wp_unique_post_slug($col,$table='wp_posts'){
     global $wpdb;

     $alphabet = array_merge( range(0, 9), range('a','z') );

     $already_exists = true;
     do {

         $guidchr = array();
         for ($i=0; $i<32; $i++)
         $guidchr[] = $alphabet[array_rand( $alphabet )];


         $guid = sprintf( "%s", implode("", array_slice($guidchr, 0, 12, true)) );

       // check that GUID is unique
       $already_exists = (boolean) $wpdb->get_var("
       SELECT COUNT($col) as the_amount FROM $table WHERE $col = '$guid'
       ");

      } while (true == $already_exists);

     return $guid;
}

當我替換post.php(wordpress核心)中的字體時,此腳本效果很好,但不幸的是,每次更新后,永久鏈接都會更改。 如何避免這種情況? 以及如何編輯自定義可選關鍵字(http://mysite.com/keyword)。

任何想法都歡迎!

讀這個

http://codex.wordpress.org/Using_Permalinks

在此處輸入圖片說明

要么

function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) {

if($slug!=""){
  $random=rand(11111,99999); //I needed 5 digit random
  $slug = $random;
}
return $slug;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM