Support » Plugins and Hacks » [Plugin: NextGEN Gallery] Clean/SEO URL solution

  • Here’s a very quick hack to demo how easy it would be to have clean, SEO friendly URL structure for *all* albums and galleries without having to resort to:

    /nggallery/page-202/album-2/gallery-3/

    1. Gallery > Options > General Options > Activate permalinks [ empty ] do not tick this box

    2. Create a new Page to act as gallery main slug (this must match 1st segment in rewrite rule, see below):

    /gallery

    3. Insert the ngg shortcode (so nextgen code is run)

    [album id=1 template=compact]

    4. Visit URL:

    http://mysite.com/gallery/album-name/gallery-name/

    File: nggfunctions.php

    Line #330 in function nggShowAlbum()

    // $_GET from wp_query
        $gallery  = get_query_var('gallery');
        $album    = get_query_var('album');
    
        global $wpdb;
        $album_result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->nggalbum WHERE name = '%s'", $album) );
        $gallery_result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->nggallery WHERE name = '%s'", $gallery ) );
    
        $album = $album_result->id;
        $gallery = $gallery_result->gid;

    File: THEME/functions.php

    add_filter('rewrite_rules_array','wp_insertMyRewriteRules');
        add_filter('query_vars','wp_insertMyRewriteQueryVars');
        add_filter('init','flushRules');
    
        // Remember to flush_rules() when adding rules
        function flushRules()
        {
            global $wp_rewrite;
            $wp_rewrite->flush_rules();
        }
    
        // Adding a new rule
        function wp_insertMyRewriteRules($rules)
        {
            $newrules = array();
            $newrules['(gallery)/([a-z\-]*)/([a-z\-]*)$'] = 'index.php?pagename=$matches[1]&album=$matches[2]&gallery=$matches[3]';
    
            return $newrules + $rules;
        }
    
        // Adding the id var so that WP recognizes it
        function wp_insertMyRewriteQueryVars($vars)
        {
            array_push($vars, 'id');
            return $vars;
        }

    http://wordpress.org/extend/plugins/nextgen-gallery/

Viewing 1 replies (of 1 total)
  • Stencil,

    This appears to be exactly what I’ve been searching for. Except it doesn’t seem to work. Can you offer a more complete walk-through of the solution? I’ve changed:
    $newrules['(gallery)/...
    to read
    $newrules['(portfolio)/...
    I have an existing page called /portfolio/. But the thumbnail links on this page still appear as ../portfolio/?album=7

    Can you help me sort out what’s missing? Your help is very much appreciated!

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: NextGEN Gallery] Clean/SEO URL solution’ is closed to new replies.