Dragâ€™nâ€™drop reorderÂing of posts, now also for cusÂtom post types and taxonomies!
You might know the pluÂgin PostÂMash, and its spinÂoff PostÂMash (filÂtered). Both very nice pluÂgÂins, allowÂing dragâ€™nâ€™drop reorderÂing of posts. EspeÂcially for those of us using WordÂPress as a CMS this is a very nice feaÂture to offer our webÂdeÂsign clients. But time went by, and neiÂther pluÂgin were ever updated for CusÂtom Post types / CusÂtom taxÂonomies, as introÂduced in WP 3.0. Enter PostÂMash Custom!
The new cusÂtom post types and cusÂtom taxÂonÂomy feaÂtures introÂduced in WP 3.0 boosted WPâ€™s capaÂbilÂiÂties as a CMS to a whole new level, and I quickly started using these new feaÂtures for my webÂdeÂsign clients, makÂing event calÂenÂdars, portÂfoÂlio sites and lots of other feaÂtures a lot easÂier to use, and more dependÂable and easÂier to cusÂtomize than beeÂing depenÂdent on pluÂgÂins for every litÂtle feaÂture. But dragâ€™nâ€™drop sortÂing of posts were sorely missed.
So, finally I had to do get someÂthing done myself. Here is the result â€” free forÂ all:
How toÂ use:
Usage is exactly the same as its preÂdeÂceÂcesÂsors postMash/filtered, so if you know/use those, you can just switch with this withÂout any furÂtherÂ work.
Then â€” in your themeâ€™s index.php-file (or whereever you want to use it), find the beginÂning of â€śthe loopâ€ť, startÂingÂ with
Directly before that, add the folÂlowÂingÂ code:
<?php $wp_query->set('orderby', 'menu_order'); $wp_query->set('order', 'ASC'); $wp_query->get_posts(); ?>
This just tells WP to get the posts ordered accordÂing to their â€śmenu_orderâ€ť posiÂtion. ThereÂfore you can get the posts ordered anyÂtime you use a funcÂtion such as get_posts simÂply by givÂing it the required arguments:
<?php get_posts('orderby=menu_order&order=ASC'); ?>
InstrucÂtions for Twenty Ten
Things may seem a bit difÂferÂent in Twenty Ten, since the loop has been moved from the indiÂvidÂual temÂplateÂfiles into loop.php, but actuÂally it still works almost exactly the same. Below is the entire code you need for Twenty Tens index.php:
<?php /** * The main template file. * * This is the most generic template file in a WordPress theme * and one of the two required files for a theme (the other being style.css). * It is used to display a page when nothing more specific matches a query. * E.g., it puts together the home page when no home.php file exists. * Learn more: http://codex.wordpress.org/Template_Hierarchy * * @package WordPress * @subpackage Twenty_Ten * @since Twenty Ten 1.0 */ get_header(); ?> <div id="container"> <div id="content" role="main"> <?php $wp_query->set('orderby', 'menu_order'); $wp_query->set('order', 'ASC'); $wp_query->get_posts(); ?> <?php /* Run the loop to output the posts. * If you want to overload this in a child theme then include a file * called loop-index.php and that will be used instead. */ get_template_part( 'loop', 'index' ); ?> </div><!-- #content --> </div><!-- #container --> <?php get_sidebar(); ?> <?php get_footer(); ?>
More info in the readme in the zip.
The pluÂgin will also be added to WPâ€™s reposÂiÂtory asap. The pluÂgin can now be downÂloaded at http://wordpress.org/extend/plugins/postmash-custom/