在wordpress中音译现有的西里尔语slug(postu name)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在wordpress中音译现有的西里尔语slug(postu name)相关的知识,希望对你有一定的参考价值。
While working on the iteration of a blog with russian contents we had to change the slugs from cyrillic to transliterated russian.[RusToLat](http://mywordpress.ru/plugins/rustolat/) is a great plugin that does just that, but unfortunately it only does the transliteration for new or "edited" posts (i.e. you have to open the post at least once and "edit" the permalink, then it will be transliterated).
Since this blog more than 500 posts this manual updating wasn't an option so we wrote this simple script. Maybe it will save somebody some time.
You'd probably better back-up your database before updating it (google for mysqldump syntax).
<?php // just a helper func to see how long it took to process slugs function microtime_float(){ return ((float)$usec + (float)$sec); } $time_start = microtime_float(); // replace %root% and %secret% with your database credentials // replace %wordpress_db% with your database $sql=""; // this dictionary is copied from the source of http://mywordpress.ru/plugins/rustolat/ // which is great, but only works for new posts // in the situtation when I had > 500 posts it was easier to write this script // than to go one by one updating slugs "��"=>"YE","��"=>"I","��"=>"G","��"=>"i","�"=>"#","��"=>"ye","��"=>"g", "��"=>"A","��"=>"B","��"=>"V","��"=>"G","��"=>"D", "��"=>"E","��"=>"YO","��"=>"ZH", "��"=>"Z","��"=>"I","��"=>"J","��"=>"K","��"=>"L", "��"=>"M","��"=>"N","��"=>"O","��"=>"P","� "=>"R", "�¡"=>"S","�¢"=>"T","�£"=>"U","�¤"=>"F","�¥"=>"X", "�¦"=>"C","�§"=>"CH","�¨"=>"SH","�©"=>"SHH","�ª"=>"'", "�«"=>"Y","�¬"=>"","Ã�ÂÂ"=>"E","�®"=>"YU","�¯"=>"YA", "�°"=>"a","�±"=>"b","�²"=>"v","�³"=>"g","�´"=>"d", "�µ"=>"e","��"=>"yo","�¶"=>"zh", "�·"=>"z","�¸"=>"i","�¹"=>"j","�º"=>"k","�»"=>"l", "�¼"=>"m","�½"=>"n","�¾"=>"o","�¿"=>"p","��"=>"r", "��"=>"s","��"=>"t","��"=>"u","��"=>"f","��"=>"x", "��"=>"c","��"=>"ch","��"=>"sh","��"=>"shh","��"=>"", "��"=>"y","��"=>"","��"=>"e","��"=>"yu","��"=>"ya","�«"=>"","�»"=>"","�"=>"-" ); // this is a name of file that will be generated to use later to actually update our DB // it can be anything you want and by default it will be created in the same directory // where this script is $myFile = "slugs_fix.sql"; # slugs $q = mysql_query("select * from wp_posts where post_status = 'publish' and post_type = 'post'", $db); $slug = $row["post_name"]; $id = $row["ID"]; // post_name is url-encoded � it's stored in a format // such as %D1%85%D0%B2%D0%BE%D1%81%D1%82 // translate the string $sql .= "update wp_posts set post_name = '" . $slug . "' where id = '" . $id . "'; "; $stringData = $sql; $sql=""; $slug=""; } $time_end = microtime_float(); $time = $time_end - $time_start; echo "Transliterated slugs in $time seconds "; // okay, the file is written // and now it can be used like this: // mysql -u root -p wordpress_db < slugs_fix.sql // after issuing this command your slugs should be updated
以上是关于在wordpress中音译现有的西里尔语slug(postu name)的主要内容,如果未能解决你的问题,请参考以下文章
Wordpress - 如何通过 slug 获取自定义帖子类型?
根据 Wordpress 中的自定义字段值批量重写帖子 slug