I got it to work eventually – this works for me (obviously try at your own risk etc. etc.)
<?php
/* copy commenty stuff here from existing version of plugin */
class PD_StickyPostsInCategory {
function PD_StickyPostsInCategory() {
return $this->__construct();
}
function __construct() {
define('PD_SPIC_VERSION', '2.1');
//e.g. /var/www/example.com/wordpress/wp-content/plugins/exit-crusher
define("PD_SPIC_DIR", plugin_dir_path(__FILE__));
//e.g. exit-crusher/exit-crusher.php
define("PD_SPIC_BASENAME", plugin_basename(__FILE__));
add_filter('the_posts', array(
$this,
'putStickyOnTop'
));
add_filter('post_class', array(
$this,
'addStickyClass'
) , 10, 3);
}
function putStickyOnTop($posts)
{
$page = 1;
if (empty($wp_query->query_vars['nopaging']) && !$wp_query->is_singular) {
$page = absint($wp_query->query_vars['paged']);
if (!$page) {
$page = 1;
}
}
// Put sticky posts at the top of the posts array
$sticky_posts = get_option('sticky_posts');
$current_category = get_cat_ID(single_term_title('', false));
if ($page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$wp_query->query_vars['ignore_sticky_posts']) {
$num_posts = count($posts);
$sticky_offset = 0;
// Loop over posts and relocate stickies to the front.
for ($i = 0;$i < $num_posts;$i++) {
if (in_array($posts[$i]->ID, $sticky_posts)) {
$sticky_post = $posts[$i];
// Remove sticky from current position
array_splice($posts, $i, 1);
// Move to front, after other stickies
array_splice($posts, $sticky_offset, 0, array(
$sticky_post
));
// Increment the sticky offset. The next sticky will be placed at this offset.
$sticky_offset++;
// Remove post from sticky posts array
$offset = array_search($sticky_post->ID, $sticky_posts);
unset($sticky_posts[$offset]);
}
}
// If any posts have been excluded specifically, Ignore those that are sticky.
if (!empty($sticky_posts) && !empty($q['post__not_in'])) {
$sticky_posts = array_diff($sticky_posts, $q['post__not_in']);
}
// Fetch sticky posts that weren't in the query results
if (!empty($sticky_posts) && !is_user_logged_in() && is_category()) {
// Prevent maximum function nesting level error
remove_filter('the_posts', array(
$this,
'the_posts'
) , 1, 2);
$stickies = get_posts(array(
'post__in' => $sticky_posts,
'post_type' => $wp_query->query_vars['post_type'],
'post_status' => 'publish',
'cat' => $current_category,
'nopaging' => true
));
add_filter('the_posts', array(
$this,
'the_posts'
) , 1, 2);
foreach ($stickies as $sticky_post) {
array_splice($posts, $sticky_offset, 0, array(
$sticky_post
));
$sticky_offset++;
}
}
}
return $posts;
}
function addStickyClass($classes, $class, $post_id) {
if (is_sticky() && !isset($classes['sticky'])) {
$classes[] = 'sticky';
}
return $classes;
}
function activate() {
}
}
$PD_StickyPostsInCategory = new PD_StickyPostsInCategory();
register_activation_hook(__FILE__, array(
'PD_StickyPostsInCategory',
'activate'
));