Making WordPress.org

Changeset 2966


Ignore:
Timestamp:
04/15/2016 09:38:17 PM (11 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Add a filter form to taxonomy archives.

Props keesiemeijer.
Fixes #601.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
5 edited

Legend:

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

    r1675 r2966  
    1616
    1717                <main id="main" class="site-main" role="main">
     18
     19                        <?php taxonomy_archive_filter(); ?>
    1820
    1921                        <?php if ( have_posts() ) : ?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/extras.php

    r2799 r2966  
    141141add_filter( 'the_title',         'wporg_filter_archive_title', 10, 2 );
    142142add_filter( 'single_post_title', 'wporg_filter_archive_title', 10, 2 );
     143
     144/**
     145 * Removes the query string from get_pagenum_link() for loop pagination.
     146 * Fixes pagination links like example.com/?foo=bar/page/2/.
     147 *
     148 * @param array  $args Arguments for the paginate_links() function.
     149 * @return array       Arguments for the paginate_links() function.
     150 */
     151function wporg_loop_pagination_args( $args ) {
     152        global $wp_rewrite;
     153
     154        // Add the $base argument to the array if the user is using permalinks.
     155        if ( $wp_rewrite->using_permalinks() && ! is_search() ) {
     156                $pagenum = trailingslashit( preg_replace( '/\?.*/', '', get_pagenum_link() ) );
     157                $pagination_base = $wp_rewrite->pagination_base;
     158               
     159                $args['base'] = user_trailingslashit(  $pagenum . "{$pagination_base}/%#%" );
     160        }
     161
     162        return $args;
     163}
     164add_filter( 'loop_pagination_args', 'wporg_loop_pagination_args' );
     165
     166/**
     167 * Removes 'page/1' from pagination links with a query string.
     168 *
     169 * @param  string $page_links Page links HTML.
     170 * @return string             Page links HTML.
     171 */
     172function wporg_loop_pagination( $page_links ) {
     173        global $wp_rewrite;
     174
     175        $pagination_base = $wp_rewrite->pagination_base;
     176        $request         = remove_query_arg( 'paged' );
     177        $query_string    = explode( '?', $request );
     178
     179        if ( isset( $query_string[1] ) ) {
     180
     181                $query_string = preg_quote( $query_string[1], '#' );
     182       
     183                // Remove 'page/1' from the entire output since it's not needed.
     184                $page_links = preg_replace(
     185                        array(
     186                                "#(href=['\"].*?){$pagination_base}/1(\?{$query_string}['\"])#",  // 'page/1'
     187                                "#(href=['\"].*?){$pagination_base}/1/(\?{$query_string}['\"])#", // 'page/1/'
     188                        ),
     189                        '$1$2',
     190                        $page_links
     191                );
     192        }
     193
     194        return $page_links;
     195}
     196add_filter( 'loop_pagination', 'wporg_loop_pagination' );
     197
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r2942 r2966  
    341341         * Get an array of all parsed post types.
    342342         *
     343         * @param string  $labels If set to 'labels' post types with their labels are returned.
    343344         * @return array
    344345         */
    345         function get_parsed_post_types() {
    346                 return array(
    347                         'wp-parser-class',
    348                         'wp-parser-function',
    349                         'wp-parser-hook',
    350                         'wp-parser-method',
     346        function get_parsed_post_types( $labels = '' ) {
     347                $post_types = array(
     348                        'wp-parser-class'    => __( 'Classes',   'wporg' ),
     349                        'wp-parser-function' => __( 'Functions', 'wporg' ),
     350                        'wp-parser-hook'     => __( 'Hooks',     'wporg' ),
     351                        'wp-parser-method'   => __( 'Methods',   'wporg' ),
    351352                );
     353
     354                if ( 'labels' !== $labels ) {
     355                        return array_keys( $post_types );
     356                }
     357
     358                return $post_types;
    352359        }
    353360
    … …  
    13941401                return $message;
    13951402        }
     1403
     1404        /**
     1405         * Displays a post type filter dropdown on taxonomy pages.
     1406         *
     1407         * @return string HTML filter form.
     1408         */
     1409        function taxonomy_archive_filter() {
     1410                global $wp_rewrite;
     1411
     1412                $taxonomies = array( 'wp-parser-since', 'wp-parser-package', 'wp-parser-source-file' );
     1413                $taxonomy   = get_query_var( 'taxonomy' );
     1414                $term       = get_query_var( 'term' );
     1415
     1416                if ( ! ( is_tax() && in_array( $taxonomy, $taxonomies ) ) ) {
     1417                        return;
     1418                }
     1419
     1420                $post_types  = get_parsed_post_types( 'labels' );
     1421                $post_types  = array( 'any' => __( 'Any type', 'wporg' ) ) + $post_types;
     1422
     1423                $qv_post_type = array_filter( (array) get_query_var( 'post_type' ) );
     1424                $qv_post_type = $qv_post_type ? $qv_post_type : array( 'any' );
     1425
     1426                $options = '';
     1427                foreach ( $post_types as $post_type => $label ) {
     1428                        $selected = in_array( $post_type, $qv_post_type ) ? " selected='selected'" : '';
     1429                        $options .= "\n\t<option$selected value='" . esc_attr( $post_type ) . "'>$label</option>";
     1430                }
     1431
     1432                $form = "<form method='get' class='archive-filter-form' action=''>";
     1433
     1434                if ( ! $wp_rewrite->using_permalinks() ) {
     1435                        // Add taxonomy and term when not using permalinks.
     1436                        $form .= "<input type='hidden' name='" . esc_attr( $taxonomy ) . "' value='" . esc_attr( $term ) . "'>";
     1437                }
     1438               
     1439                $form .= "<label for='archive-filter'>";
     1440                $form .= __( 'Filter by type:', 'wporg' ) . ' ';
     1441                $form .= '<select name="post_type[]" id="archive-filter">';
     1442                $form .= $options . '</select></label>';
     1443                $form .= "<input class='shiny-blue' type='submit' value='Filter' /></form>";
     1444
     1445                echo $form;
     1446        }
    13961447}
     1448
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss

    r2810 r2966  
    671671                                }
    672672                        }
     673                }
     674        }
     675
     676        .archive-filter-form {
     677                margin: 5rem 0;
     678                font-size: 1.5rem;
     679                input[type="submit"] {
     680                        margin-left: .5em;
     681                        padding: 0.2em 0.5em;
     682                        line-height: 1;
     683                        font-size: 1.5rem;
    673684                }
    674685        }
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css

    r2810 r2966  
    913913  line-height: 36px;
    914914}
     915.devhub-wrap .archive-filter-form {
     916  margin: 5rem 0;
     917  font-size: 1.5rem;
     918}
     919.devhub-wrap .archive-filter-form input[type="submit"] {
     920  margin-left: .5em;
     921  padding: 0.2em 0.5em;
     922  line-height: 1;
     923  font-size: 1.5rem;
     924}
    915925.devhub-wrap .searchform {
    916926  overflow: hidden;
Note: See TracChangeset for help on using the changeset viewer.