Making WordPress.org


Ignore:
Timestamp:
02/17/2015 11:18:19 PM (9 years ago)
Author:
obenland
Message:

WP.org Themes: Use main query instead of Themes API for server output.

  • Can now deal properly with /browse/*/ URL structure.
  • Adds single theme navigation.
  • Adds Photon support for server output.
  • Brings single theme view closer to melchoyce's mockups.

See #745.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/functions.php

    r1243 r1274  
    5555
    5656/**
    57  * Makes an API request to retrieve the right themes for the current query.
    58  *
    59  * @param WP_Query $query
    60  * @return WP_Query
    61  */
    62 function wporg_themes_set_up_query( $query ) {
    63     if ( is_admin() || in_array( $query->query_vars['pagename'], array( 'upload', 'commercial' ) ) || 'nav_menu_item' == $query->get( 'post_type' ) ) {
    64         return $query;
    65     }
    66 
    67     $query->set( 'post_type', 'repopackage' );
    68 
    69     $args = array(
    70         'per_page' => 15,
    71         'fields'   => array(
    72             'description'  => true,
    73             'sections'     => false,
    74             'tested'       => true,
    75             'requires'     => true,
    76             'rating'       => true,
    77             'downloaded'   => true,
    78             'downloadlink' => true,
    79             'last_updated' => true,
    80             'homepage'     => true,
    81             'tags'         => true,
    82             'num_ratings'  => true,
    83             'parent'       => true,
    84         ),
    85     );
    86 
    87     if ( $query->query_vars['tag'] ) {
    88         $args['tag'][] = $query->query_vars['tag'];
    89     }
    90     elseif ( $query->query_vars['author_name'] ) {
    91         $args['author'] = $query->query_vars['author_name'];
    92     }
    93     elseif ( $query->query_vars['pagename'] ) {
    94         $slugs = explode( '/', $query->query_vars['pagename'] );
    95 
    96         if ( count( $slugs ) > 1 && 'browse' == $slugs[0] ) {
    97             $args['browse'] = $slugs[1];
    98         } else {
    99             $args['theme'] = $slugs[0];
    100         }
    101     }
    102     else {
    103         $args['browse'] = 'featured';
    104     }
    105 
    106     if ( ! function_exists( 'themes_api' ) ) {
    107         include ABSPATH . 'wp-admin/includes/theme.php';
    108     }
    109     $GLOBALS['themes'] = themes_api( 'query_themes', $args );
    110 
    111     return $query;
    112 }
    113 add_filter( 'pre_get_posts', 'wporg_themes_set_up_query' );
    114 
    115 /**
    11657 * Enqueue scripts and styles.
    11758 */
     
    12364    wp_enqueue_style( 'wporg-themes-style', get_stylesheet_uri() );
    12465
    125     wp_enqueue_script( 'google-jsapi', '//www.google.com/jsapi', array(), null );
     66    wp_enqueue_script( 'google-jsapi', '//www.google.com/jsapi', array( 'jquery' ), null );
    12667
    12768    if ( ! is_singular( 'page' ) ) {
     
    199140 */
    200141function wporg_themes_api_args( $args, $action ) {
    201     if ( 'query_themes' == $action ) {
     142    if ( in_array( $action, array( 'query_themes', 'theme_information' ) ) ) {
    202143        $args->per_page = 30;
    203144        $args->fields['parent']  = true;
Note: See TracChangeset for help on using the changeset viewer.