Eric @ EricBess WebHome

一味思考而不行动,将在不知不觉中变得无意义

Chinese (Simplified) flagItalian flagKorean flagPortuguese flagEnglish flagGerman flagFrench flagSpanish flagJapanese flagArabic flagRussian flagGreek flagDutch flagBulgarian flagCzech flagCroat flagDanish flagFinnish flagHindi flagPolish flagRumanian flagSwedish flagNorwegian flagCatalan flagFilipino flagHebrew flagIndonesian flagLatvian flagLithuanian flagSerbian flagSlovak flagSlovenian flagUkrainian flagVietnamese flag
By N2H

Rewrite Permalinks in plugin development.

We add a rewrite rule that tells WordPress to interpret /geostate/oregon URLs the same as ?geostate=oregon.
there are two steps:

(1) "flush" the cached rewrite rules using an init filter, to force WordPress to recalculate the rewrite rules,
add_action('init', 'geotags_flush_rewrite_rules');

function geotags_flush_rewrite_rules()
{
   global $wp_rewrite;
   $wp_rewrite->flush_rules();
}
(2) use the generate_rewrite_rules action to add a new rule when they are calculated. Here's the "flush" code:
add_action('generate_rewrite_rules', 'geotags_add_rewrite_rules');

function geotags_add_rewrite_rules( $wp_rewrite )
{
  $new_rules = array(
     'geostate/(.+)' => 'index.php?geostate=' .
       $wp_rewrite->preg_index(1) );

  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
-欢迎为本文评级

相关日志

本文读者也关心以下内容:

  • N/A

07月 7th, 2008 作者: eric | Wordpress Programming | Trackback ? | 无评论| Email This Post Print This Post | 47 views

Add a Comment

Leave a reply

No Comments