Forums

Help with rewrite rules (6 posts)

  1. flipflops
    Member
    Posted 5 years ago #

    Hi

    I'm writing a simple gallery plugin.But am unable to get anywhere with the rewrite rules, I was hoping that somebody could help or point me in the right direction.

    The premise behind my plugin works like this: When a user writes a post they can include a string in the page (e.g. my_gallery_goes_here) that is filtered using add_filter('the_content'... and replaced with the front of the gallery. This works fine.

    What the viewer sees then is a set of images that represent the albums within the gallery. When the viewer clicks on the image I want them to go to a page called /gallery/some_album which shows the a set of images and from there to /gallery/some_album/some_picture

    The page 'gallery' will have the string my_gallery_goes_here in it which will then be replaced with the gallery using the_content. I want to a pass the values some_album and some_picture to the gallery function.

    I've searched the docs etc. - but just can't figure out how to create the rewrite rule in wordpress - any help or advice would be greatly appreciated.

    Cheers

    p.s. I'm using 2.1

  2. hannah071
    Member
    Posted 5 years ago #

    Have you tried just adding a rule to the .htaccess file?

    At least that way you can get it working... the documentation for a lot of the filers and actions is pretty thin, sometimes you can work things out from the source code, but sometimes wordpress is just to tangled up...

  3. flipflops
    Member
    Posted 5 years ago #

    I'm going to have a go at that this morning - see what happens - the thing is in an ideal world I want to be able to do it all via the wordpress API.

    Thanks

  4. Otto
    Tech Ninja
    Posted 5 years ago #

    Using the WP_Rewrite stuff is tricky, at best.

    In 2.1.x, it was made quite a bit simpler, although documentation is still pretty spotty. If you are using 2.1.x, look closely at rewrite.php, and read these as well:
    http://codex.wordpress.org/User%3ADavidHouse/WP_Rewrite_API
    http://trac.wordpress.org/ticket/2433

  5. flipflops
    Member
    Posted 5 years ago #

    Thanks Otto - I hadn't come accross either of those. I'll have read through and see how I get on.

  6. flipflops
    Member
    Posted 5 years ago #

    I've got it cracked - I found this post http://wordpress.org/support/topic/62400?replies=9 - which helped me figure it out.

    For the moment I'm just going to use a simple rewrite rule to get /gallery/... to resolve to my plugin function and then take it apart with $_SERVER['REQUEST_URI']

Topic Closed

This topic has been closed to new replies.

About this Topic