Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //following is in functions.php (inside the theme folder)
- if (isset($_GET['sort'])) {
- $sort = $_GET['sort'];
- }
- add_filter('posts_join', 'votes_join');
- add_filter('posts_where', 'votes_where');
- add_filter('posts_orderby', 'votes_orderby');
- function votes_join($join)
- {
- global $sort;
- if (is_front_page() && !empty($sort)) {
- if ($sort == 1 || $sort == 2){
- $join = "LEFT JOIN wp_xbhuui_wpv_voting ON wp_xbhuui_posts.ID = wp_xbhuui_wpv_voting.post_id";
- }
- }
- return $join;
- }
- function votes_where($where)
- {
- global $sort;
- if (is_front_page() && !empty($sort)) {
- if ($sort == 1) {
- $where .= "AND (post_date > DATE_SUB(NOW(), INTERVAL 1 DAY) OR wp_xbhuui_posts.ID = '31' OR wp_xbhuui_posts.ID = '2' OR wp_xbhuui_posts.ID = '5' OR wp_xbhuui_posts.ID = '1018')";
- }
- elseif ($sort == 2) {
- $where .= "AND (post_date > DATE_SUB(NOW(), INTERVAL 7 DAY) OR wp_xbhuui_posts.ID = '31' OR wp_xbhuui_posts.ID = '2' OR wp_xbhuui_posts.ID = '5' OR wp_xbhuui_posts.ID = '1018')";
- }
- else {
- //no sort selected, do nothing
- }}
- return $where;
- }
- function votes_orderby ($orderby)
- {
- global $sort;
- if (is_front_page() && !empty($sort)) {
- if ($sort == 1 || $sort == 2){
- $orderby = "vote_count DESC";
- }
- }
- return $orderby;
- }
- //following is in top of index.php template file
- global $sort;
- $sort = 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement