Skip to content

Commit

Permalink
Learn: Sync with git WordPress/Learn@1d9c732
Browse files Browse the repository at this point in the history
git-svn-id: https://meta.svn.wordpress.org/sites/trunk@11558 74240141-8908-4e6f-9713-ba540dce6ec7
  • Loading branch information
dd32 committed Feb 15, 2022
1 parent 968c991 commit 8c36a0e
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace WordPressdotorg\Theme;

$prev_category = '';
$category = '';

get_header(); ?>

<main id="main" class="site-main">
Expand All @@ -24,6 +27,21 @@
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) :
the_post();

$display_category = false;
$categories = get_the_terms( get_the_ID(), 'course-category' );
if ( isset( $categories[0] ) ) {
$category = $categories[0]->name;
if ( $category != $prev_category ) {
$display_category = true;
$prev_category = $category;
}
}

if ( $display_category ) {
echo '<h2 class="h4 course-category-header">' . esc_html( $category ) . '</h2>';
}

get_template_part(
'template-parts/component',
'card',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@import "../../../wporg/css/components/wporg-header";
@import "card";
@import "content-icon";
@import "course-archive";
@import "featured-workshop";
@import "filter-drawer";
@import "locale-notice";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h2.course-category-header {
flex-basis: 100%;
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,17 @@ function wporg_archive_modify_query( WP_Query $query ) {
),
)
);

$query->set(
'tax_query',
array(
array(
'taxonomy' => 'course-category',
'field' => 'id',
'terms' => get_terms( 'course-category', array( 'fields' => 'ids' ) ),
),
)
);
}

// Omit some post types from search results.
Expand Down Expand Up @@ -378,6 +389,26 @@ function wporg_archive_modify_query( WP_Query $query ) {
}
add_action( 'pre_get_posts', 'wporg_archive_modify_query' );

/**
* Add ordering to query for advanced filtering
*
* @param string $orderby
* @param object $query
*
* @return string
*/
function wporg_archive_orderby( $orderby, $query ) {
global $wpdb;

// Group courses by their category
if ( $query->is_main_query() && $query->is_post_type_archive( 'course' ) ) {
$orderby = $wpdb->term_relationships . '.term_taxonomy_id DESC, ' . $orderby;
}

return $orderby;
}
add_filter( 'posts_orderby', 'wporg_archive_orderby', 10, 2 );

/**
* Modify the workshop post type archive query to prioritize workshops in the user's locale.
*
Expand Down

0 comments on commit 8c36a0e

Please sign in to comment.