[wp-hackers] Adding rewrite rules to wp
Gerhard Brauckmann
Gerhard.Brauckmann at mi-verlag.de
Mon Oct 1 09:19:39 GMT 2007
Dear friends of WP, I would like to add a rule to WP.
I took the example from the WP Codex and did also some digging within
Jeromes TAGs plugin.
I cant get it running. So I got some specific questions:
- when using the Codex example, do I have to add the query_var also into
wp_rewrite?
see my example here:
/* add PARTS List to specific POST */
/* example: http://mydomain/2007/09/31/xmas-tools-44/part/334 */
/* this should pass to post /2007/09/31/xmas-tools-44 */
/* whithin single.php axtract query_var (part) with token 334 - do
somenting with the value */
/* finish */
class MI_Parts {
function MI_Parts() {
add_action('init', array(&$this, 'mi_initRewrite')); //
can't use WP rewrite flags until "init" hook
} // end of initialization
/* function from Jeromes Keywords */
function mi_initRewrite() {
global $wp_rewrite;
/* detect permalink type & construct base URL for local links */
$base_url = get_settings('home') . '/';
if (isset($wp_rewrite) && $wp_rewrite->using_permalinks()) {
$rewriteon = true; // using rewrite rules
$base_url .= $wp_rewrite->root; // set to
"index.php/" if using that style
$base_url .= 'part/';
} else {
$base_url .= '?part=';
}
/* generate rewrite rules for tag queries */
if ($rewriteon)
add_filter('post_rewrite_rules', array(&$this,
'mi_createRewriteRules'));
/* flush rules if requested */
$initdone = true;
if ($flushrules)
$wp_rewrite->flush_rules();
}
/* function from Jeromes Keywords */
function mi_createRewriteRules($rewrite) {
global $wp_rewrite;
/* add rewrite tokens */
$qvar ="part";
$token = '%' . $qvar . '%';
$wp_rewrite->add_rewrite_tag($token, '(.+)', $qvar . '=');
$keywords_structure = $wp_rewrite->root . $qvar . "/$token";
$keywords_rewrite =
$wp_rewrite->generate_rewrite_rules($keywords_structure);
return ( $rewrite + $keywords_rewrite );
}
} // of CLASS
with this code I'm expecting someting like [..../part/ ..] in the
wp_rewrite_rules list (array) but there ist still nothing
What is worng here? (Im using WP 2.3)
Regards
Gerhard Brauckmann
More information about the wp-hackers
mailing list