Posted By

dottDesign on 04/29/10


Tagged

textmate page wordpress order custom


Versions (?)

Wordpress Page Order


 / Published in: Other
 

Add to functions.php/* Page Order */include('library/functions/page-order.php');

  1. <?php
  2. /* Version 2.8b - http://www.geekyweekly.com/mypageorder */
  3. function mypageorder_menu()
  4. { if (function_exists('add_submenu_page')) {
  5. add_submenu_page(mypageorder_getTarget(), 'Page Order', __('Page Order', 'mypageorder'), 5,"mypageorder",'mypageorder');
  6. }
  7. }
  8.  
  9. function mypageorder_js_libs() {
  10. if ( $_GET['page'] == "mypageorder" ) {
  11. wp_enqueue_script('jquery');
  12. wp_enqueue_script('jquery-ui-core');
  13. wp_enqueue_script('jquery-ui-sortable');
  14. }
  15. }
  16.  
  17. //Switch page target depending on version
  18. function mypageorder_getTarget() {
  19. global $wp_version;
  20. if (version_compare($wp_version, '2.6.5', '>'))
  21. return "page-new.php";
  22. else
  23. return "edit.php";
  24. }
  25.  
  26. add_action('admin_menu', 'mypageorder_menu');
  27. add_action('admin_menu', 'mypageorder_js_libs');
  28.  
  29. function mypageorder() {
  30. global $wpdb;
  31. $mode = "";
  32. $mode = $_GET['mode'];
  33. $parentID = 0;
  34. if (isset($_GET['parentID']))
  35. $parentID = $_GET['parentID'];
  36. $success = "";
  37.  
  38. if($mode == "act_OrderPages") {
  39. $idString = $_GET['idString'];
  40. $IDs = explode(",", $idString);
  41. $result = count($IDs);
  42.  
  43. for($i = 0; $i < $result; $i++)
  44. {
  45. $wpdb->query("UPDATE $wpdb->posts SET menu_order = '$i' WHERE id ='$IDs[$i]'");
  46. }
  47. $success = '<div id="message" class="updated fade"><p>'. __('Page order updated successfully.', 'mypageorder').'</p></div>';
  48. }
  49.  
  50. $subPageStr = "";
  51. $results=$wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = $parentID and post_type = 'page' ORDER BY menu_order ASC");
  52. foreach($results as $row)
  53. {
  54. $postCount=$wpdb->get_row("SELECT count(*) as postsCount FROM $wpdb->posts WHERE post_parent = $row->ID and post_type = 'page' ", ARRAY_N);
  55. if($postCount[0] > 0)
  56. $subPageStr = $subPageStr."<option value='$row->ID'>$row->post_title</option>";
  57. }
  58. ?>
  59. <div class='wrap'>
  60. <h2><?php _e('Page Order', 'mypageorder') ?></h2>
  61. <?php echo $success; ?>
  62. <p><?php _e('Choose a page from the drop down to order its subpages or order the pages on this level by dragging and dropping them into the desired order.', 'mypageorder') ?></p>
  63.  
  64. <?php
  65. if($parentID != 0)
  66. {
  67. $parentsParent = $wpdb->get_row("SELECT post_parent FROM $wpdb->posts WHERE ID = $parentID ", ARRAY_N);
  68. echo "<a href='". mypageorder_getTarget() . "?page=mypageorder&parentID=$parentsParent[0]'>" . __('Return to parent page', 'mypageorder') . "</a>";
  69. }
  70. if($subPageStr != "") { ?>
  71. <h3><?php _e('Order Subpages', 'mypageorder') ?></h3>
  72. <select id="pages" name="pages"><?php
  73. echo $subPageStr;
  74. ?>
  75. </select>
  76. &nbsp;<input type="button" name="edit" Value="<?php _e('Order Subpages', 'mypageorder') ?>" onClick="javascript:goEdit();">
  77. <?php } ?>
  78.  
  79. <h3><?php _e('Order Pages', 'mypageorder') ?></h3>
  80. <ul id="order" style="width: 500px; margin:10px 10px 10px 0px; padding:10px; border:1px solid #B2B2B2; list-style:none;"><?php
  81. foreach($results as $row)
  82. {
  83. echo "<li id='$row->ID' class='lineitem'>$row->post_title</li>";
  84. }?>
  85. </ul>
  86.  
  87. <input type="button" id="orderButton" Value="<?php _e('Click to Order Pages', 'mypageorder') ?>" onclick="javascript:orderPages();">&nbsp;&nbsp;<strong id="updateText"></strong>
  88.  
  89. </div>
  90.  
  91. <style>
  92. li.lineitem {
  93. margin: 3px 0px;
  94. padding: 2px 5px 2px 5px;
  95. background-color: #F1F1F1;
  96. border:1px solid #B2B2B2;
  97. cursor: move;
  98. width: 490px;
  99. }
  100. </style>
  101.  
  102. <script language="JavaScript">
  103.  
  104. jQuery(document).ready(function(){
  105. jQuery("#order").sortable({
  106. placeholder: "ui-selected",
  107. revert: false,
  108. tolerance: "pointer"
  109. });
  110. });
  111.  
  112. function orderPages() {
  113. jQuery("#orderButton").css("display", "none");
  114. jQuery("#updateText").html("<?php _e('Updating Page Order...', 'mypageorder') ?>");
  115.  
  116. idList = jQuery("#order").sortable("toArray");
  117. location.href = '<?php echo mypageorder_getTarget(); ?>?page=mypageorder&mode=act_OrderPages&parentID=<?php echo $parentID; ?>&idString='+idList;
  118. }
  119.  
  120. function goEdit () {
  121. if(jQuery("#pages").val() != "")
  122. location.href="<?php echo mypageorder_getTarget(); ?>?page=mypageorder&mode=dsp_OrderPages&parentID="+jQuery("#pages").val();
  123. }
  124. </script>
  125. <?php
  126. }
  127. ?>

Report this snippet  

You need to login to post a comment.