Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

We want the users to re-order the posts on a page similar to pagination but I can't find anything anywhere!

It would be great to create a link to a url similar to .../page/2/title/, title being the new order. Is this even possible?!

Found several pagination scripts but none offer this option...

share|improve this question
    
Try appending the URL of the page with the order and/or order by you want, eg. example.com/somepage/page/2/?order=desc&orderby=title ..both the order and orderby parameters are public query variables(ie. you can query by them directly in the URL). –  t31os Mar 30 '11 at 13:12
    
ah cool! Think there's a way to make em safe URLs? –  daniel Crabbe Mar 30 '11 at 13:24
    
I'd suggest updating your question to reflect what you're asking regarding creating pretty URLs(since this is now the primary basis of your question). Additionally it may help to have a quick search for custom rewrite rule related topics to get an idea of what's involved with creating custom rules. –  t31os Mar 30 '11 at 14:23
add comment

1 Answer

up vote 1 down vote accepted

Adding a rewrite rule with an order part is very easy, if you do it for one site. It would be harder if you want to create a generic solution that works for all installations with all kinds of permalink structures and custom taxonomies.

This short example works on a basic install of WordPress 3.1, with no extra custom taxonomies. I use the orderby prefix to prevent conflicts with existing post names:

add_action( 'init', 'wpse13483_init' );
function wpse13483_init()
{
    add_rewrite_rule( 'category/(.+?)/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?category_name=$matches[1]&paged=$matches[4]&orderby=$matches[2]', 'top' );
    add_rewrite_rule( 'tag/([^/]+)/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?tag=$matches[1]&paged=$matches[4]&orderby=$matches[2]', 'top' );
    add_rewrite_rule( 'type/([^/]+)/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?post_format=$matches[1]&paged=$matches[4]&orderby=$matches[2]', 'top' );
    add_rewrite_rule( 'author/([^/]+)/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?author_name=$matches[1]&paged=$matches[4]&orderby=$matches[2]', 'top' );
    add_rewrite_rule( '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[6]&orderby=$matches[4]', 'top' );
    add_rewrite_rule( '([0-9]{4})/([0-9]{1,2})/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[5]&orderby=$matches[3]', 'top' );
    add_rewrite_rule( '([0-9]{4})/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?year=$matches[1]&paged=$matches[4]&orderby=$matches[2]', 'top' );
}
share|improve this answer
    
hey jan - thanks for this! It seems to be the way forward but i can't seem to get it to work with the URL bfami.modernactivity.co.uk/category/educational-projects/page/2/…. I know it should be the first rule but it doesn't catch? –  daniel Crabbe Apr 5 '11 at 16:01
    
@daniel: I forgot to recommend my Rewrite analyzer plugin, which shows you the current rewrite rules and lets you experiment with URLs. Remember that you should flush your rules too, by visiting the Permalinks page. –  Jan Fabry Apr 5 '11 at 16:04
    
ah - got the working after re-saving my permalink settings! Also managed to incorp order/asc or desc too so thanks very much. –  daniel Crabbe Apr 5 '11 at 16:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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