Making WordPress.org


Ignore:
Timestamp:
11/02/2020 09:04:14 PM (5 years ago)
Author:
coreymckrill
Message:

WordPress.org Learn: Sync with GitHub

https://github.com/WordPress/learn/compare/ae6bd868368aaed4c7fe6ab1fdeb98261dbd88ca...d6f49fad358bed0aa29b92047257b2ecbddbbec6

File:
1 edited

Legend:

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

    r10272 r10422  
    249249 * @return void
    250250 */
    251 function wporg_workshop_modify_query( WP_Query $query ) {
     251function wporg_archive_modify_query( WP_Query $query ) {
    252252    if ( is_admin() ) {
    253253        return;
    254254    }
    255255
    256     if ( $query->is_main_query() && $query->is_post_type_archive( 'wporg_workshop' ) ) {
    257         wporg_workshop_maybe_apply_query_filters( $query );
    258 
    259         if ( true !== $query->get( 'wporg_workshop_filters' ) ) {
     256    $valid_post_types = array( 'lesson-plan', 'wporg_workshop' );
     257
     258    if ( $query->is_main_query() && $query->is_post_type_archive( $valid_post_types ) ) {
     259        wporg_archive_maybe_apply_query_filters( $query );
     260
     261        if ( $query->is_post_type_archive( 'wporg_workshop' ) && true !== $query->get( 'wporg_workshop_filters' ) ) {
    260262            $featured = wporg_get_featured_workshops();
    261263
     
    271273    }
    272274}
    273 add_action( 'pre_get_posts', 'wporg_workshop_modify_query' );
     275add_action( 'pre_get_posts', 'wporg_archive_modify_query' );
    274276
    275277/**
     
    280282 * @return void
    281283 */
    282 function wporg_workshop_maybe_apply_query_filters( WP_Query &$query ) {
     284function wporg_archive_maybe_apply_query_filters( WP_Query &$query ) {
    283285    $filters = filter_input_array(
    284286        INPUT_GET,
     
    364366 * Get a query object for displaying workshop posts.
    365367 *
     368 * @param string $post_type The post type of the archive.
     369 * @param array  $args      Arguments for the query.
     370 *
    366371 * @return WP_Query
    367372 */
    368 function wporg_get_workshops_query( array $args = array() ) {
     373function wporg_get_archive_query( $post_type, array $args = array() ) {
    369374    $args = wp_parse_args( $args, array(
    370         'post_type'   => 'wporg_workshop',
     375        'post_type'   => $post_type,
    371376        'post_status' => 'publish',
    372377    ) );
     
    386391 */
    387392function wporg_get_featured_workshops( $number = 1 ) {
    388     $query = wporg_get_workshops_query( array(
    389         'posts_per_page' => $number,
    390     ) );
     393    $query = wporg_get_archive_query(
     394        'wporg_workshop',
     395        array(
     396            'posts_per_page' => $number,
     397        )
     398    );
    391399
    392400    return $query->get_posts();
     
    498506
    499507/**
     508 * Append pagination to the archive title.
     509 *
     510 * @global WP_Query $wp_query
     511 * @global int $paged
     512 *
     513 * @param string $title
     514 *
     515 * @return mixed
     516 */
     517function wporg_modify_archive_title( $title ) {
     518    global $wp_query, $paged;
     519
     520    if ( $paged > 1 ) {
     521        $suffix = sprintf(
     522            __( 'Page %1$d of %2$d', 'wporg-learn' ),
     523            absint( $paged ),
     524            absint( $wp_query->max_num_pages )
     525        );
     526
     527        $title = sprintf(
     528            // translators: 1: Archive title; 2: Pagination, e.g. Page 2 of 4.
     529            __( '%1$s – %2$s', 'wporg-learn' ),
     530            $title,
     531            $suffix
     532        );
     533    }
     534
     535    return $title;
     536}
     537add_filter( 'get_the_archive_title', 'wporg_modify_archive_title' );
     538
     539/**
    500540 * Get the series taxonomy term object for a workshop post.
    501541 *
Note: See TracChangeset for help on using the changeset viewer.