0

Hey there, I am sooo frustrated, asked and asked and can't seem to get an answer. Pleaseeeee help, I'll be very very clean whith my problem. I'll give hundreds of bears to the one who can help:)

  1. I have a blog installed http://www.myblog.com - it's part of a network, I use wordpress multisite

  2. I created a table called cars with 60 rows - it's not a wordpress table, it's my own custom table but I have created it inside the wordpress database.

  3. On my blog theme, editing index.php, I display the records from the table cars, 10 rows per page and I write a custom pagination script with no relation what so ever with my wordpress pagination.

  4. Now i have the following links:
    www.myblog.com/index.php?currentpage=1
    www.myblog.com/index.php?currentpage=2
    and so on untill ...
    www.myblog.com/index.php?currentpage=6

  5. How can I rewrite them to pretty goole friendly links?

Ideea one: since they are not actually related to the wordpress blog, should I edit htaccess? I believe wordpress .htacces rules override any custom rules i put there... if you know a solution please share...

Ideea two: Tried to use wordpress rules and edited functions.php like so, with no luck:

add_action( 'init', 'wpa5413_init' ); 
    function wpa5413_init() {     
        add_rewrite_rule(           
            '^/\?currentpage/(\d*)$',         
            'index.php?currentpage=$matches[1]',  
            'top' ); 
    }

    add_filter('query_vars', 'wpa3537_query_vars'); 
    function wpa3537_query_vars($query_vars) {     
        $query_vars[] = 'currentpage';     
        return $query_vars;
    } 

Please help me, honestly, I can even pay, I am soo frustraed... doing this work after my dayjob, it's been days of not sleeping, just need to make this happen, pleaseeeeeeeeeeeeeeeee

PS don't vote down my question, i see others are struggeling with similar issues

2 Answers 2

0

Your rewrite rules must not start with the first slash, that is already stripped out. So the following code will add a rewrite rule that will set a query variable that we can later use:

add_action( 'init', 'wpse9016_init' );
function wpse9016_init()
{
    add_rewrite_rule( 'currentpage/(\d+)/?', 'index.php?wpse9016_currentpage=$matches[1]', 'top' );
}

This query variable is ignored unless we add it to the list of public query variables:

add_action( 'query_vars', 'wpse9016_query_vars' );
function wpse9016_query_vars( $query_vars )
{
    $query_vars[] = 'wpse9016_currentpage';
    return $query_vars;
}

After you have done this, you can check for it and do whatever you want when it is set. A common use is to load a specific template file:

add_filter( 'template_include', 'wpse9016_template_include' );
function wpse9016_template_include( $template )
{
    if ( get_query_var( 'wpse9016_currentpage' ) ) {
        $template = locate_template( array( 'wpse9016_template.php' ) );
    }
    return $template;
}

Now, if you go to http://www.example.com/currentpage/2/, the file wpse9016_template.php in your theme directory will be loaded, where you can read get_query_var( 'wpse9016_currentpage' ) to get the current page number.

2
  • Oh my god, you have no ideea how much i have struggled with this and I'm almost there, you are awesome, tyyyyyyyy, cheers! :) I have just one issue, on my index.page where I have the pagination links, the links won't be rewrited by the server. It's great if i type in my browser ezample.com/currentpage/2, but on my index.php i still get example.com/?currentpage=2... Why? TY TY TY
    – webmasters
    Feb 10, 2011 at 19:48
  • @webmasters: You have to generate the new style of links yourself, WordPress does not do this for you (unlike other platforms with a complete routing system). What code do you currently use to write the pagination links?
    – Jan Fabry
    Feb 10, 2011 at 21:48
0

What kind of "pretty Google friendly links" do you mean exactly?

Rather than messing with the rewrite rules, it may be easier to move your custom code to a custom page template, then add a new Page which uses that template, then set your site home page to that static page in Settings > Reading.

Again though - not sure what you want to have happen for the pagination. Sorry if I'm way off base in trying to help! :)

2
  • Something like: www.myblog.com/index.php?currentpage=1 turns into www.myblog.com/currentpage/1 or something like that, Ty sooo much
    – webmasters
    Feb 9, 2011 at 21:28
  • Well, if you use a Page with a custom template, you'll get to www.myblog.com/pagename just fine (assuming you have pretty Permalinks enabled in Settings > Permalinks). Since your pagination depends on the custom code you've written, you could then shorten it down at least so it would read www.myblog.com/pagename?p=1 etc. I don't think that Google will detract in any way for having that bit of pagination in the URL - it will just see /pagename.
    – Michelle
    Feb 9, 2011 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.