-
Notifications
You must be signed in to change notification settings - Fork 0
/
blogcaravan.php
57 lines (49 loc) · 1.46 KB
/
blogcaravan.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/*
Plugin Name: Blogcaravan
Plugin URI: http://gibberish.com/hacks/wp/blogcaravan/
Description: Show the posts on your home page, and date and category archives, in the order in which they've been commented on (newest first). Posts with no comments will be merged into the order by their post date.
Version: 0.1
Author: Mike Sugarbaker
Author URI: http://gibberish.com/
License: http://creativecommons.org/licenses/GPL/2.0/
*/
function bcv_test($wp_q) {
print_r($wp_q);
return $wp_q;
}
function bcv_fields($fields) {
global $wpdb;
if (is_home() || is_archive() || is_category()) {
return "$wpdb->posts.*
, cd.max_comment_date
, cast((case when cd.comment_post_ID is null then $wpdb->posts.post_date else cd.max_comment_date end) as datetime) as order_by_date";
}
return $fields;
}
function bcv_join($join) {
global $wpdb;
if (is_home() || is_archive() || is_category()) {
return "left outer join
(
select c.comment_post_ID
, max(c.comment_date) as max_comment_date
from $wpdb->comments c
group by c.comment_post_ID
) cd
on $wpdb->posts.id = cd.comment_post_ID
";
}
return $join;
}
function bcv_order($orderby) {
if (is_home() || is_archive() || is_category()) {
return "order_by_date desc";
}
return $orderby;
}
add_filter('posts_fields', 'bcv_fields');
add_filter('posts_join', 'bcv_join');
add_filter('posts_orderby', 'bcv_order');
// add_filter('posts_request','bcv_test');
?>