::GAME2.TW::臺灣遊戲攻略

華語手機遊戲攻略,遊戲資訊專業網站

WordPress SimpleTags的修改建議

  WordPress在2.3版本以前出過不少Tags插件,自從WordPress 2.3支持Tags後,這些第三方插件大多轉換為管理和維護系統自帶Tags的功能,其中比較出名的是SimpleTags插件,這個插件有中文語言包,使用起來比較方便。

  不過我在使用過程中,發現SimpleTags最新版本1.2.4的“批量編輯標籤”有部分缺陷,我這裡給出了兩個缺陷的修改方法:

  1、 搜索功能(Search terms)存在問題:SimpleTags使用了全文的搜索,只要文章內容包含關鍵字就匹配,這會造成大量錯誤匹配,我將其修改為只匹配文章的標題。

  修改:simple-tags\inc\simple-tags.admin.php文件,找到1466行,將原來的

  $search_sql = "AND ( (post_title LIKE '% {$search}%') OR (post_content LIKE '%{$search}%') )";

  修改為:

  $search_sql = "AND ( (post_title LIKE '%{$search}%') OR (post_title LIKE '%{$search}%') )";

  2、無標籤搜索(untagged only)存在問題:當文章數量非常大的時候,這個功能會出現錯誤,不返回正常的內容,我將原先代碼中的SQL語句進行了修改,大大提高了搜索效率和速度。

  修改:simple-tags\inc\simple-tags.admin.php文件,找到1475行,將原來的

$p_id_used = $wpdb->get_col("
SELECT DISTINCT term_relationships.object_id
FROM {$wpdb->term_taxonomy} term_taxonomy, {$wpdb->term_relationships} term_relationships, {$wpdb->posts} posts
WHERE term_taxonomy. taxonomy = 'post_tag'
AND term_taxonomy.term_taxonomy_id = term_relationships.term_taxonomy_id
AND term_relationships.object_id  = posts.ID
AND posts.post_type = '{$type}'");

$filter_sql = 'AND ID NOT IN ("'.implode( '", "', $p_id_used ).'")';

  修改為:

$p_id_used = "SELECT DISTINCT term_relationships.object_id
FROM {$wpdb->term_taxonomy} term_taxonomy, {$wpdb->term_relationships} term_relationships, {$wpdb->posts} posts
WHERE term_taxonomy.taxonomy = 'post_tag'
AND term_taxonomy.term_taxonomy_id = term_relationships.term_taxonomy_id
AND term_relationships.object_id  = posts.ID
AND posts.post_type = '{$type }'";

$filter_sql = 'AND ID NOT IN ('.$p_id_used.')';

  經過這兩處修改,SimpleTags的批量修改日誌Tag的功能中就比較好用了。

文章轉載月光博客