Making WordPress.org

Ticket #601: 601.patch

File 601.patch, 6.8 KB (added by keesiemeijer, 9 years ago)

Add a filter form to taxonomy archives

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

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

     
    140140}
    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' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

     
    340340        /**
    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
    354361        /**
     
    13711378
    13721379                return $message;
    13731380        }
     1381
     1382        /**
     1383         * Displays a post type filter dropdown on taxonomy pages.
     1384         *
     1385         * @return string HTML filter form.
     1386         */
     1387        function taxonomy_archive_filter() {
     1388                global $wp_rewrite;
     1389
     1390                $taxonomies = array( 'wp-parser-since', 'wp-parser-package', 'wp-parser-source-file' );
     1391                $taxonomy   = get_query_var( 'taxonomy' );
     1392                $term       = get_query_var( 'term' );
     1393
     1394                if ( !( is_tax() && in_array( $taxonomy, $taxonomies ) ) ) {
     1395                        return;
     1396                }
     1397
     1398                $post_types  = get_parsed_post_types( 'labels' );
     1399                $post_types  = array( 'any' => __( 'Any type', 'wporg' ) ) + $post_types;
     1400
     1401                $qv_post_type = array_filter( (array) get_query_var( 'post_type' ) );
     1402                $qv_post_type = !empty( $qv_post_type ) ? $qv_post_type : array( 'any' );
     1403
     1404                $options = '';
     1405                foreach ( $post_types as $post_type => $label ) {
     1406                        $selected = in_array( $post_type, $qv_post_type ) ? " selected='selected'" : '';
     1407                        $options .= "\n\t<option$selected value='" . esc_attr( $post_type ) . "'>$label</option>";
     1408                }
     1409
     1410                $form = "<form method='get' class='archive-filter-form' action=''>";
     1411
     1412                if ( !$wp_rewrite->using_permalinks() ) {
     1413                        // Add taxonomy and term when not using permalinks
     1414                        $form .= "<input type='hidden' name='$taxonomy' value='$term'>";
     1415                }
     1416               
     1417                $form .= "<label for='archive-filter'>";
     1418                $form .= __( 'Filter by type:', 'wporg' ) . ' ';
     1419                $form .= '<select name="post_type[]" id="archive-filter">';
     1420                $form .= $options . '</select></label>';
     1421                $form .= "<input class='shiny-blue' type='submit' value='Filter' /></form>";
     1422
     1423                echo $form;
     1424        }
    13741425}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss

     
    673673                }
    674674        }
    675675
     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.1;
     683                        font-size: 1.5rem;
     684                }
     685        }
     686
    676687        .searchform {
    677688                overflow: hidden;
    678689                height: auto;
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css

     
    912912  font-size: 36px;
    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.1;
     923  font-size: 1.5rem;
     924}
    915925.devhub-wrap .searchform {
    916926  overflow: hidden;
    917927  height: auto;