[wp-hackers] Adding rewrite rules to wp

Austin Matzko if.website at gmail.com
Mon Oct 1 12:53:56 GMT 2007


On 10/1/07, Gerhard Brauckmann <Gerhard.Brauckmann at mi-verlag.de> wrote:
> /* 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 */

I think the following is what you want, as it will set a query var of
"part" to "334" for something like
"http://mydomain/2007/09/31/xmas-tools-44/part/334":

function MI_Parts() {
       add_action('init', array(&$this, 'mi_initRewrite'));
       add_filter('post_rewrite_rules', array(&$this, 'mi_createRewriteRules'));
} // end of initialization

function mi_initRewrite() {
        add_rewrite_tag('%part%', 'part/(.+)');
}

function mi_createRewriteRules($rewrite) {
        global $wp_rewrite;
        $keywords_structure = $wp_rewrite->permalink_structure . "%part%/";
        $keywords_rewrite =
$wp_rewrite->generate_rewrite_rules($keywords_structure,
EP_PERMALINK);
        return ( $rewrite + $keywords_rewrite );
}
} // of CLASS


More information about the wp-hackers mailing list