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…
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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' );
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0