Making WordPress.org

Changeset 1286


Ignore:
Timestamp:
02/20/2015 02:29:04 AM (10 years ago)
Author:
obenland
Message:

WP.org Themes: Finish browse setups.

  • To achieve parity between server-side and API results of featured themes, the

API will continue to be responsible for determining which themes are featured.
It will store the featured theme's post IDs in cache, for the directory to use.

  • We'll use the same query adjustment as in the API to get the same ouput of

popular themes.

  • New themes will just be the latest themes, much like blog posts.

See #745.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php

    r1274 r1286  
    104104                $wp_query->set( 'paged', 1 );
    105105                $wp_query->set( 'posts_per_page', 15 );
    106                 $wp_query->set( 'date_query', array(
    107                     array(
    108                         'column' => 'post_modified_gmt',
    109                         'after'  => '-1 year',
    110                     ),
    111                 ) );
    112                 $wp_query->set( 'orderby', 'rand' );
     106                $wp_query->set( 'post__in', (array) wp_cache_get( 'browse-popular', 'theme-info' ) );
    113107                break;
    114108
    115109            case 'popular':
    116                 //TODO: Sort by popularity.
     110                add_filter( 'posts_clauses',  'wporg_themes_popular_posts_clauses' );
    117111                break;
    118112
    119113            case 'new':
     114                // Nothing to do here.
    120115                break;
    121116        }
     
    141136}
    142137add_filter( 'found_posts', 'wporg_themes_found_posts', 10, 2 );
     138
     139/**
     140 * Filters SQL clauses, to set up a query for the most popular themes based on downloads.
     141 *
     142 * @param array $clauses
     143 * @return array
     144 */
     145function wporg_themes_popular_posts_clauses( $clauses ) {
     146    global $wpdb;
     147
     148    $week = gmdate( 'Y-m-d', strtotime( 'last week' ) );
     149    $clauses['where']  .= " AND s.stamp >= '{$week}'";
     150    $clauses['groupby'] = "{$wpdb->posts}.ID";
     151    $clauses['join']    = "JOIN bb_themes_stats AS s ON ( {$wpdb->posts}.post_name = s.slug )";
     152    $clauses['orderby'] = 'week_downloads DESC';
     153    $clauses['fields'] .= ', SUM(s.downloads) AS week_downloads';
     154
     155    return $clauses;
     156}
    143157
    144158/**
Note: See TracChangeset for help on using the changeset viewer.