sticky = $table_prefix . 'sticky'; ### Function: Sticky Option Menu add_action('admin_menu', 'sticky_menu'); function sticky_menu() { if (function_exists('add_options_page')) { add_options_page(__('WP-Sticky', 'wp-sticky'), __('WP-Sticky', 'wp-sticky'), 'manage_options', 'sticky/sticky-options.php'); } } ### Function: Get Sticky Option function get_sticky_option($option) { $sticky_options = get_option('sticky_options'); return $sticky_options[$option]; } ### Function: Check Whether In Category if(!function_exists('check_in_category')) { function check_in_category() { $category_base = get_option('category_base'); if(empty($category_base)) { $category_base = '/category'; } if(strpos($_SERVER['REQUEST_URI'], $category_base) !== false || intval($_GET['cat']) > 0) { return true; } return false; } } ### Function: Sticky Query if(intval(get_sticky_option('category_only')) == 1) { if(check_in_category()) { add_filter('posts_fields', 'sticky_fields'); //add_filter('posts_join', 'sticky_join'); add_filter('posts_join_paged', 'sticky_join'); add_filter('posts_orderby', 'sticky_orderby', 1); } } else { add_filter('posts_fields', 'sticky_fields'); //add_filter('posts_join', 'sticky_join'); add_filter('posts_join_paged', 'sticky_join'); add_filter('posts_orderby', 'sticky_orderby', 1); } function sticky_fields($content) { global $wpdb; $content .= ", $wpdb->sticky.sticky_status"; return $content; } function sticky_join($content) { global $wpdb; $content .= " LEFT JOIN $wpdb->sticky ON $wpdb->sticky.sticky_post_id = $wpdb->posts.ID"; return $content; } function sticky_orderby($content) { global $wpdb; $content = "($wpdb->sticky.sticky_status = 2 AND $wpdb->sticky.sticky_status IS NOT NULL) DESC, DATE_FORMAT($wpdb->posts.post_date,'%Y-%m-%d') DESC, ($wpdb->sticky.sticky_status = 1 AND $wpdb->sticky.sticky_status IS NULL) DESC, DATE_FORMAT($wpdb->posts.post_date,'%T') DESC"; return $content; } ### Function: Output Post Sticky Status, Sticky Or Announcement function post_sticky_status($before = '', $after = '', $display = true) { global $id, $post; $temp = ''; switch($post->sticky_status) { case 1: $temp = $before.__('Sticky', 'wp-sticky').$after; break; case 2: $temp = $before.__('Announcement', 'wp-sticky').$after; break; } if($display) { echo $temp; } else { return $temp; } } ### Function: If Sticky Condition function is_sticky() { global $id, $post; if($post->sticky_status == 1) { return true; } else { return false; } } ### Function: If Announcement Condition function is_announcement() { global $id, $post; if($post->sticky_status == 2) { return true; } else { return false; } } ### Function: Display Announcement Banner function announcement_banner($display = true) { global $post, $printed_announcement; if($post->sticky_status == 2 && intval(get_sticky_option('display_date')) == 0) { if($printed_announcement) { return; } else { $printed_announcement = true; if($display) { echo get_sticky_option('announcement_banner'); } else { return get_sticky_option('announcement_banner'); } } } return $content; } ### Function: Sticky The Date add_filter('the_date', 'sticky_the_date'); function sticky_the_date($content) { global $post, $previousday, $printed_announcement; if($post->sticky_status == 2 && intval(get_sticky_option('display_date')) == 0) { $previousday = ''; if($printed_announcement) { return; } else { $printed_announcement = true; return get_sticky_option('announcement_banner'); } } return $content; } ### Function: Sticky The Title add_filter('the_title', 'sticky_the_title'); function sticky_the_title($content) { global $post; if(strpos($_SERVER['REQUEST_URI'], '/edit.php') !== false && ($post->sticky_status > 0)) { $content = post_sticky_status('', '', false).': '.$content; } return $content; } ### Function: Sticky The Content //add_filter('the_content', 'sticky_the_content'); function sticky_the_content($content) { global $post; $css_style = ''; switch($post->sticky_status) { case 1: $css_style = ""; break; case 2: $css_style = ""; break; } return $css_style.$content; } ### Function: Processing Sticky Post add_action('save_post', 'add_sticky_admin_process'); function add_sticky_admin_process($post_ID) { global $wpdb; $post_status_sticky_status = intval($_POST['post_status_sticky']); // Normal Posts if($post_status_sticky_status == 0 && intval($post_ID) > 0) { $wpdb->query("DELETE FROM $wpdb->sticky WHERE sticky_post_id = $post_ID"); // Sticky Post/Announcement Post } else { // Ensure No Duplicate Field $check = intval($wpdb->get_var("SELECT sticky_status FROM $wpdb->sticky WHERE sticky_post_id = $post_ID")); if($check == 0) { $wpdb->query("INSERT INTO $wpdb->sticky VALUES($post_ID, $post_status_sticky_status)"); } else { $wpdb->query("UPDATE $wpdb->sticky SET sticky_status = $post_status_sticky_status WHERE sticky_post_id = $post_ID"); } } } ### Function: Delete Away Sticky If Post Is Deleted add_action('delete_post', 'delete_sticky_admin_process'); function delete_sticky_admin_process($post_ID) { global $wpdb; $wpdb->query("DELETE FROM $wpdb->sticky WHERE sticky_post_id = $post_ID"); } ### Function: Add Sticky To Admin add_action('dbx_post_sidebar', 'sticky_admin'); function sticky_admin() { global $wpdb; $edit_post = intval($_GET['post']); $post_status_sticky_id = 0; $post_status_sticky_status = 0; if($edit_post > 0) { $post_status_sticky_status = intval($wpdb->get_var("SELECT sticky_status FROM $wpdb->sticky WHERE sticky_post_id = $edit_post")); } ?>

sticky (". "sticky_post_id bigint(20) NOT NULL,". "sticky_status tinyint(1) NOT NULL default '0',". "PRIMARY KEY (sticky_post_id))"; maybe_create_table($wpdb->sticky, $create_sticky_sql); // Add Options $sticky_options = array(); $sticky_options['category_only'] = 0; $sticky_options['display_date'] = 0; $sticky_options['announcement_banner'] = __('Announcement', 'wp-sticky'); add_option('sticky_options', $sticky_options, 'Sticky Options'); } ?>