Sticky post for WordPress 0.72 as implemented by LaughingLizard (http://dinki.mine.nu/weblog/) (The database changes remain same between 0.72 and 1.0) This hack requires a small change to be made to the database. I have provided three different methods to do this. If you have phpMyAdmin installed on your server, find your database, click on wp_posts (could be *anyprefix*posts), click on Structure and then on post_status and find the length/values column where the following line should be present: 'publish', 'draft', 'private' Just add ,'sticky' to the line so the final value looks like so: 'publish', 'draft', 'private', 'sticky' If you dont have phpMyAdmin, you could use the mysql command line to change it using the following command after you have logged onto your mysel server and have chosen a database to work on (remember to change your table prefix according to your blog, mine is b2 so I have b2posts. If your table prefix is wp_, you would use wp_posts as the table name below): ALTER TABLE `b2posts` CHANGE `post_status` `post_status` ENUM( 'publish', 'draft', 'private', 'sticky' ) DEFAULT 'publish' NOT NULL Consequently, here is the php code to run from a webpage, if thats your cup of tea. $sql = 'ALTER TABLE `b2posts` CHANGE `post_status` `post_status` ENUM( \'publish\', \'draft\', \'private\', \'sticky\' ) DEFAULT \'publish\' NOT NULL '; ###STEP 1### ==FIND(only for 0.72)== Find in wp-edit.form.php (inside your wp-admin directory): For version 1.0 (referred to as 1.0 from now on) find edit-form-advanced.php inside wp-admin directory: Find this:
==REPLACE== In 0.72, Replace with this: In 1.0, replace with this: ###STEP 2### ==FIND 0.72== In 0.72 Find these lines in your blog.header.php: if ($pagenow != 'b2edit.php') { if ((empty($poststart)) || (empty($postend)) || !($postend > $poststart)) { $where .= ' AND post_date <= \''.$now.'\''; } $where .= ' AND post_category > 0'; $distinct = 'DISTINCT'; if ($use_gzipcompression) { // gzipping the output of the script gzip_compression(); } } $where .= ' AND (post_status = "publish"'; // Get private posts if ('' != intval($user_ID)) $where .= " OR post_author = $user_ID AND post_status != 'draft')"; else $where .= ')'; $request = " SELECT $distinct * FROM $tableposts WHERE 1=1".$where." ORDER BY post_$orderby $limits"; ==REPLACE 0.72== In 0.72 Replace with these lines: if ($pagenow != 'b2edit.php') { if ((empty($poststart)) || (empty($postend)) || !($postend > $poststart)) { $where .= ' AND post_date <= \''.$now.'\''; } $where .= ' AND post_category > 0'; $distinct = 'DISTINCT'; if ($use_gzipcompression) { // gzipping the output of the script gzip_compression(); } } $where .= ' AND (post_status = "publish" OR post_status = "sticky"'; // Get private posts if ('' != intval($user_ID)) $where .= " OR post_author = $user_ID AND post_status != 'draft')"; else $where .= ')'; $request = " SELECT $distinct * FROM $tableposts WHERE 1=1".$where." ORDER BY post_status DESC, post_$orderby $limits"; Be careful to leave the ?> at the end of the blog.header.php. ==FIND 1.0== In 1.0, Find these lines in your wp-blog-header.php: if ($pagenow != 'post.php') { if ((empty($poststart)) || (empty($postend)) || !($postend > $poststart)) { $where .= ' AND post_date <= \''.$now.'\''; } $distinct = 'DISTINCT'; if ($use_gzipcompression) { // gzipping the output of the script gzip_compression(); } } $where .= ' AND (post_status = "publish"'; // Get private posts if (isset($user_ID) && ('' != intval($user_ID))) $where .= " OR post_author = $user_ID AND post_status != 'draft')"; else $where .= ')'; $request = " SELECT $distinct * FROM $tableposts $join WHERE 1=1".$where." ORDER BY post_$orderby $limits"; ==REPLACE 1.0== In 1.0, replace with these lines: if ($pagenow != 'post.php') { if ((empty($poststart)) || (empty($postend)) || !($postend > $poststart)) { $where .= ' AND post_date <= \''.$now.'\''; } $distinct = 'DISTINCT'; if ($use_gzipcompression) { // gzipping the output of the script gzip_compression(); } } $where .= ' AND (post_status = "publish" OR post_status = "sticky"'; // Get private posts if (isset($user_ID) && ('' != intval($user_ID))) $where .= " OR post_author = $user_ID AND post_status != 'draft')"; else $where .= ')'; $request = " SELECT $distinct * FROM $tableposts $join WHERE 1=1".$where." ORDER BY post_status DESC, post_$orderby $limits"; ==Find in 1.01+ (in wp-blog-header.php)== $comment_counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount FROM $tableposts LEFT JOIN $tablecomments ON ( comment_post_ID = ID AND comment_approved = '1') WHERE post_status = 'publish' AND ID IN ($post_id_list) GROUP BY ID"); ==Replace with in 1.01+ == $comment_counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount FROM $tableposts LEFT JOIN $tablecomments ON ( comment_post_ID = ID AND comment_approved = '1') WHERE (post_status = 'publish' OR post_status = 'sticky') AND ID IN ($post_id_list) GROUP BY ID"); ==FIND 1.0== Find this line in your wp-admin/edit-form.php: ==ADD 1.0== Add this line below it: ==FIND 1.0== Find this line in your wp-admin/post.php: if ('' != $HTTP_POST_VARS['saveasprivate']) $post_status = 'private'; ==ADD 1.0== Add this line below it: if ('' != $HTTP_POST_VARS['saveassticky']) $post_status = 'sticky'; All done! Now to implement this hack, simply choose "sticky" as the post option in a post and it will show up on top of your blog no matter what time or date it is. To remove the sticky, simply edit the post and change the status back to publish.