AStickyPostOrderER

"; //echo ""; if ($croer) { // we are returning here with a bit of work to do switch($croer) { case 1: echo "\n"; require_once('croer-transact.php'); break; case 2: echo "\n"; require_once('croer-meta-transact.php'); break; } } if ($cat == NULL) { // no cat in hand thus start by giving choice of categories"; _e("

Sorties: Click a category or tag's name below to manually create an order of some or all of its contained posts to be shown before the default ordered posts in that category or tag, or re-arange all posts as they apear on home and archive pages.
- AND / OR -
Meta: Use the radio buttons to specify meta-stickyness, respectively:

  1. Super-sticky: Show before anything else
    (you can set a limit for how many posts from this cat or tag should be given this preferential treatment)
  2. Sub-sticky: Show after individually ordered posts for given view but before on-sorted posts
  3. Default: Treat normally (except for individually ordered posts)
  4. Droppy: Show only after everything else
and remember to click 'update meta-stickyness' at the bottom of this page for your changes to, ahemmm, 'stick'…

"); echo ''; _e('Order Index, Archive and Search Results Order'); echo ''; echo ' | '; _e('Learn More'); echo ''; echo ' | '; _e('Please Donate'); echo ''; _e(' | Problems or sugestions…? mail me at andre@pixelplexus.co.za

'); $meta_old = croer_get_meta(); ?>



AStickyPostOrderER Editing order of posts '); if ($cat==0) { _e(' in Index/Archive view'); } else { _e(' in '.c_catname($cat)); } _e(''); ?>

Enter a position number (e.g. '1') in the text field to the right of any posts to send the coresponding posts to that position. Enter '0' to remove that posts from the list of sorted posts.

To affect these changes click 'Save and Refresh' beneath the list.

or
Select a different category to re-order."; } } // this modifies the query used to display posts on the front-end and on Manage Posts function croer_the_sort($the_wp_query) { global $wp_query; //echo "wpquery query_vars:
"; //var_dump($wp_query); //echo "
-- the sort --
".urldecode($the_wp_query)."\n
"; //var_dump($the_wp_query); $c_query = $the_wp_query; $aspo = $_GET['aspo']; // can come via querystr or query_posts // aspo=vanilla : don't use astickypostorderer for this listing = done // wp_query causes havoc, can't see if query we are dealing with is from main request or a secondary loop :-/ if((!$wp_query->is_admin)&&(!$wp_query->is_single)&&(1==1)&&($aspo!='vanilla')&&($wp_query->query_vars['aspo']!='vanilla')) { //!$wp_query->is_page &&($wp_query->query_vars['in_the_loop']) //echo ""; global $wpdb; if((is_category())||(is_tag())||(strstr($c_query,'taxonomy.term_id IN '))) { // //echo "
Cat or tag!!!
"; global $wp_query; $current_term_id = $wp_query->get_queried_object_id(); } else { //echo "NOT Cat!!!"; } //echo "
original:
".$c_query."
"; // - - - - // ar $meta_posts_list defines meta sticky filters for ordering the query results // $meta_posts_list['1'] ... rank1 $meta_posts_list = array(); $get_meta_terms_sql = "SELECT term_id, limit_to, term_type FROM ".$wpdb->prefix."croer_meta WHERE term_rank =1"; $result_meta_terms = mysql_query($get_meta_terms_sql); if($result_meta_terms) { while($c_row = mysql_fetch_array($result_meta_terms)) { //print_r($c_row); extract($c_row); if ($limit_to >0) { $limiter = "LIMIT 0, $limit_to "; } else { $limiter = ""; } if ($term_type == 'cat') { $c_type = 'category'; } if ($term_type == 'tag') { $c_type = 'post_tag'; } $c_meta_term_posts_sql = "SELECT ID FROM ".$wpdb->prefix."posts LEFT JOIN ".$wpdb->prefix."term_relationships ON ( ID = object_id ) LEFT JOIN ".$wpdb->prefix."term_taxonomy ON ( ".$wpdb->prefix."term_relationships.term_taxonomy_id = ".$wpdb->prefix."term_taxonomy.term_taxonomy_id ) LEFT JOIN ".$wpdb->prefix."croer_meta ON ( ".$wpdb->prefix."term_taxonomy.term_id = ".$wpdb->prefix."croer_meta.term_id ) WHERE ".$wpdb->prefix."croer_meta.term_id = '$term_id' AND ".$wpdb->prefix."term_taxonomy.taxonomy = '$c_type' $limiter"; ///asc put in order by CRoer, post date DESC $result_meta_posts = mysql_query($c_meta_term_posts_sql); while ($c_meta_post = mysql_fetch_array($result_meta_posts)) { //echo "...".$c_meta_post['ID']; $meta_posts_list['1'][] = $c_meta_post['ID']; } } } //echo "

meta post list = "; //print_r($meta_posts_list['1']); if ($meta_posts_list['1']) { $c_ranks1 = ', '.$wpdb->prefix.'posts.ID IN '."('".join($meta_posts_list['1'], "','")."')".' AS rank1 '; $c_rank1_o = 'rank1 DESC, '; } else { $c_ranks1 = NULL; $c_rank1_o = ''; } //echo "
c_ranks1=".$c_ranks1."
"; // - - - - - - - - -- - --- - - - - - - - - // sub-sticky colection ? $get_meta_terms_sql = "SELECT term_id, term_type FROM ".$wpdb->prefix."croer_meta WHERE term_rank = 2"; $result_meta_terms = mysql_query($get_meta_terms_sql); if($result_meta_terms){ while($c_row = mysql_fetch_array($result_meta_terms)) { extract($c_row); if ($term_type == 'cat') { $c_type = 'category'; } if ($term_type == 'tag') { $c_type = 'post_tag'; } $c_meta_term_posts_sql = "SELECT ID FROM ".$wpdb->prefix."posts LEFT JOIN ".$wpdb->prefix."term_relationships ON ( ID = object_id ) LEFT JOIN ".$wpdb->prefix."term_taxonomy ON ( ".$wpdb->prefix."term_relationships.term_taxonomy_id = ".$wpdb->prefix."term_taxonomy.term_taxonomy_id ) LEFT JOIN ".$wpdb->prefix."croer_meta ON ( ".$wpdb->prefix."term_taxonomy.term_id = ".$wpdb->prefix."croer_meta.term_id ) WHERE ".$wpdb->prefix."croer_meta.term_id = '$term_id' AND ".$wpdb->prefix."term_taxonomy.taxonomy = '$c_type' "; $result_meta_posts = mysql_query($c_meta_term_posts_sql); while ($c_meta_post = mysql_fetch_array($result_meta_posts)) { //echo "...".$c_meta_post['ID']; $meta_posts_list['2'][] = $c_meta_post['ID']; } } } //echo "

meta2 post list = "; //print_r($meta_posts_list['2']); if ($meta_posts_list['2']) { $c_ranks2 = ', '.$wpdb->prefix.'posts.ID IN '."('".join($meta_posts_list['2'], "','")."')".' AS rank2 '; $c_rank2_o = 'rank2 DESC, '; } else { $c_ranks2 = NULL; $c_rank2_o = ''; } // - - - - - - - - -- - --- - - - - - - - - // droppy colection? $get_meta_terms_sql = "SELECT term_id, term_type FROM ".$wpdb->prefix."croer_meta WHERE term_rank = 4"; $result_meta_terms = mysql_query($get_meta_terms_sql); if($result_meta_terms){ while($c_row = mysql_fetch_array($result_meta_terms)) { extract($c_row); if ($term_type == 'cat') { $c_type = 'category'; } if ($term_type == 'tag') { $c_type = 'post_tag'; } $c_meta_term_posts_sql = "SELECT ID FROM ".$wpdb->prefix."posts LEFT JOIN ".$wpdb->prefix."term_relationships ON ( ID = object_id ) LEFT JOIN ".$wpdb->prefix."term_taxonomy ON ( ".$wpdb->prefix."term_relationships.term_taxonomy_id = ".$wpdb->prefix."term_taxonomy.term_taxonomy_id ) LEFT JOIN ".$wpdb->prefix."croer_meta ON ( ".$wpdb->prefix."term_taxonomy.term_id = ".$wpdb->prefix."croer_meta.term_id ) WHERE ".$wpdb->prefix."croer_meta.term_id = '$term_id' AND ".$wpdb->prefix."term_taxonomy.taxonomy = '$c_type' "; $result_meta_posts = mysql_query($c_meta_term_posts_sql); while ($c_meta_post = mysql_fetch_array($result_meta_posts)) { //echo "...".$c_meta_post['ID']; $meta_posts_list['4'][] = $c_meta_post['ID']; } } } //echo "

meta4 post list = "; //print_r($meta_posts_list['4']); if ($meta_posts_list['4']) { $c_ranks4 = ', '.$wpdb->prefix.'posts.ID IN '."('".join($meta_posts_list['4'], "','")."')".' AS rank4 '; $c_rank4_o = 'rank4 ASC, '; } else { $c_ranks4 = NULL; $c_rank4_o = ''; } $c_into = strpos($c_query, "FROM "); $c_query = substr_replace($c_query, $c_ranks1.', '.$wpdb->prefix.'croer_posts.post_rank IS NULL AS isnull '.$c_ranks2.$c_ranks4 , $c_into, 0); $c_into = strpos($c_query, "WHERE "); if($current_term_id){$tmp_catid_str = ' AND '.$wpdb->prefix.'croer_posts.cat_id = '.$current_term_id.' ';} if (strpos($c_query, "$wpdb->term_taxonomy.term_id")) { //echo "
if
"; $c_query = substr_replace($c_query, 'LEFT JOIN '.$wpdb->prefix.'croer_posts ON ('.$wpdb->posts.'.ID = '.$wpdb->prefix.'croer_posts.post_id'.$tmp_catid_str.' ) ', $c_into, 0);// AND '.$wpdb->term_taxonomy.'.term_id = '.$wpdb->prefix.'croer_posts.cat_id AND } else { //echo "
else
"; $c_query = substr_replace($c_query, 'LEFT JOIN '.$wpdb->prefix.'croer_posts ON ('.$wpdb->posts.'.ID = '.$wpdb->prefix.'croer_posts.post_id AND '.$wpdb->prefix.'croer_posts.cat_id = 0) ', $c_into, 0); } $c_into = strpos($c_query, "ORDER BY ")+9; $c_query = substr_replace($c_query, "$c_rank1_o isnull ASC, ".$wpdb->prefix."croer_posts.post_rank ASC, $c_rank2_o$c_rank4_o", $c_into, 0); //echo "
edited:
".$c_query."
"; } //echo "\n

".urldecode($c_query)."\n
prefix."croer_posts"; $meta_table_name = $wpdb->prefix."croer_meta"; // if create from scratch // this orders POSTS by cat or tag $sql = "CREATE TABLE " . $table_name . " ( croer_id bigint( 20 ) NOT NULL AUTO_INCREMENT , post_id bigint( 20 ) NOT NULL , cat_id int( 10 ) NOT NULL , post_rank bigint( 20 ) NOT NULL , PRIMARY KEY croer_id( croer_id ) );"; // Meta-stick: this makes an entire Cat or Tag Super-sticky, sub-sticky or droppy // 1= before stickys, 2= after but before default, 3= after everything else $meta_sql = "CREATE TABLE " . $meta_table_name . " ( cmeta_id bigint( 20 ) NOT NULL AUTO_INCREMENT , term_id int( 10 ) NOT NULL , term_rank int( 3 ) NULL , limit_to int( 3 ) NULL , term_type tinytext NULL, PRIMARY KEY cmeta_id( cmeta_id ) );"; //? if(@is_file(ABSPATH.'/wp-admin/upgrade-functions.php')) { include_once(ABSPATH.'/wp-admin/upgrade-functions.php'); } elseif(@is_file(ABSPATH.'/wp-admin/includes/upgrade.php')) { include_once(ABSPATH.'/wp-admin/includes/upgrade.php'); } else { die('We have problem finding your \'/wp-admin/upgrade-functions.php\' and \'/wp-admin/includes/upgrade.php\''); } //? if($wpdb->get_var("show tables like '$table_name'") != $table_name) { require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); add_option("croer_db_version", $croer_db_version); } if($wpdb->get_var("show tables like '$meta_table_name'") != $meta_table_name) { require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($meta_sql); add_option("croer_metadb_version", $croer_metadb_version ); } // in case of upgrading $installed_ver = get_option( "croer_db_version" ); if( $installed_ver != $croer_db_version ) { require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); update_option( "croer_db_version", $croer_db_version ); } $installed_metaver = get_option( "croer_metadb_version" ); if( $installed_metaver != $croer_db_version ) { require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($meta_sql); update_option( "croer_metadb_version", $croer_metadb_version ); } } function croer_delete($deleted_post_id){ // user just deleted post: $deleted_post_id, removing it from ordered posts as well global $wpdb; $sql = "DELETE FROM `".$wpdb->prefix."croer_posts` WHERE `".$wpdb->prefix."croer_posts`.`croer_id` = $deleted_post_id"; $result = mysql_query($sql); // no error handeling for the time being, maybe later } function croer_version() { echo "\n \n"; } ?>