Changeset 10422 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php
- Timestamp:
- 11/02/2020 09:04:14 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php
r10272 r10422 249 249 * @return void 250 250 */ 251 function wporg_ workshop_modify_query( WP_Query $query ) {251 function wporg_archive_modify_query( WP_Query $query ) { 252 252 if ( is_admin() ) { 253 253 return; 254 254 } 255 255 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' ) ) { 260 262 $featured = wporg_get_featured_workshops(); 261 263 … … 271 273 } 272 274 } 273 add_action( 'pre_get_posts', 'wporg_ workshop_modify_query' );275 add_action( 'pre_get_posts', 'wporg_archive_modify_query' ); 274 276 275 277 /** … … 280 282 * @return void 281 283 */ 282 function wporg_ workshop_maybe_apply_query_filters( WP_Query &$query ) {284 function wporg_archive_maybe_apply_query_filters( WP_Query &$query ) { 283 285 $filters = filter_input_array( 284 286 INPUT_GET, … … 364 366 * Get a query object for displaying workshop posts. 365 367 * 368 * @param string $post_type The post type of the archive. 369 * @param array $args Arguments for the query. 370 * 366 371 * @return WP_Query 367 372 */ 368 function wporg_get_ workshops_query(array $args = array() ) {373 function wporg_get_archive_query( $post_type, array $args = array() ) { 369 374 $args = wp_parse_args( $args, array( 370 'post_type' => 'wporg_workshop',375 'post_type' => $post_type, 371 376 'post_status' => 'publish', 372 377 ) ); … … 386 391 */ 387 392 function 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 ); 391 399 392 400 return $query->get_posts(); … … 498 506 499 507 /** 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 */ 517 function 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 } 537 add_filter( 'get_the_archive_title', 'wporg_modify_archive_title' ); 538 539 /** 500 540 * Get the series taxonomy term object for a workshop post. 501 541 *
Note: See TracChangeset
for help on using the changeset viewer.