[wp-hackers] Custom Permalinks - how to?

Niels Hackius niels at hackius.de
Tue Jun 13 18:45:22 GMT 2006


Fellow Wordpress-Hackers,
I asked this in the forums (http://wordpress.org/support/topic/75123),
but I didn't get an answer:
I am working on a plugin for the singapore-image-gallery (sgal.org).
What I would like to do is create permalinks that are calling a
certain page. Usually I create a page and singapore creates links like
this:
wordpress.com/index.php/foto/?gallery=test
The gallery is called test. The page title is "foto". Now I would like
it to look like this:
wordpress.com/index.php/gallery/test and point to the above URL.

Now I have a function like this:

	function singaporeRewriteRules($rules)
	{
		global $wp_rewrite;

		// add rewrite tokens
		$keytag_token = '%gallery%';
		//$rewrite->page_structure = $rewrite->page_structure."/".$keytag_token;
		$wp_rewrite->add_rewrite_tag($keytag_token, '(.+)',
'page_id='.get_option('singapore_page').'&gallery=');
		
		$keywords_structure = $wp_rewrite->root ."gallery/$keytag_token";
		$keywords_rewrite = $wp_rewrite->generate_rewrite_rule($keywords_structure);

		return ( $rules+$keywords_rewrite );
	}

	add_action('rewrite_rules_array',array($this,'singaporeRewriteRules'));

What it outputs in the rewrite-rule-Array is this:
[index.php/gallery/(.+)/?$] => index.php?page_id=67&gallery=$matches[1]

This obviously doesn't work. I also tried to create links like this:
* [index.php/fotos/gallery/(.+)/?$] => index.php?page_id=67&gallery=$matches[1]
* [index.php/(fotos)/gallery/(.+)/?$] =>
index.php?page_id=67&gallery=$matches[1]
* [index.php/fotos/gallery/?$] => index.php?gallery=$matches[1]

But it didn't work either, maybe someone could help me out, please?

Thank you very much,
Niels Hackius


More information about the wp-hackers mailing list