From a401a56b0e68025813f97fb6f67ec1d14d810736 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 28 Feb 2023 12:19:52 -0300 Subject: [PATCH] Adds table and grid view modes for Terms List. #59. --- src/assets/scss/_list-post.scss | 2 +- src/assets/scss/_tainacan-terms-list.scss | 69 +++++--- src/functions.php | 32 +--- src/functions/archive-functions.php | 107 ++++++++++++ src/functions/single-functions.php | 31 ---- src/style.css.map | 2 +- src/tainacan/archive-terms.php | 153 +++++++----------- .../loop-tainacan-terms-grid.php | 33 ++++ .../loop-tainacan-terms-table.php | 55 +++++++ src/template-parts/loop-tainacan-terms.php | 33 ++++ 10 files changed, 336 insertions(+), 181 deletions(-) create mode 100644 src/functions/archive-functions.php create mode 100644 src/template-parts/loop-tainacan-terms-grid.php create mode 100644 src/template-parts/loop-tainacan-terms-table.php create mode 100644 src/template-parts/loop-tainacan-terms.php diff --git a/src/assets/scss/_list-post.scss b/src/assets/scss/_list-post.scss index 6b9194d..e986af3 100644 --- a/src/assets/scss/_list-post.scss +++ b/src/assets/scss/_list-post.scss @@ -243,7 +243,7 @@ line-height: 0.75rem; } .tainacan-list-collection--grid-img { - width: 275px; + width: 250px; height: 250px; } .image-placeholder { diff --git a/src/assets/scss/_tainacan-terms-list.scss b/src/assets/scss/_tainacan-terms-list.scss index 951b99a..2894856 100644 --- a/src/assets/scss/_tainacan-terms-list.scss +++ b/src/assets/scss/_tainacan-terms-list.scss @@ -1,31 +1,58 @@ .tainacan-taxonomy-terms-list-container .tainacan-taxonomy-terms-list { - display: grid; - grid-template-columns: repeat(auto-fit, 425px); - grid-gap: 30px; list-style: none; - .term-name { - font-size: 1.125rem !important; + &.tainacan-list-collection--container-card { + display: grid; + grid-template-columns: repeat(auto-fit, 425px); + grid-gap: 30px; + + .term-name { + font-size: 1.125rem !important; + } + + .term-description p { + margin-top: 0; + padding-top: 0 !important; + padding-left: 1rem; + } + + .term-children-link a { + margin-bottom: 1.5rem; + } + + .term-items-link a { + margin-bottom: 1.5rem; + } + + .term-thumbnail { + float: left; + margin-bottom: 0; + width: 136px !important; + height: 136px !important; + } } - .term-description p { - margin-top: 0; - padding-top: 0 !important; - padding-left: 1rem; - } + &.tainacan-list-collection--container-grid { + + .term-name { + margin-bottom: 0.25rem; + font-size: 1.125rem !important; + } - .term-children-link a { - margin-bottom: 1.5rem; - } + .term-children-link a { + margin-bottom: 1.5rem; + } - .term-items-link a { - margin-bottom: 1.5rem; - } + .term-items-link a { + margin-bottom: 1.5rem; + } - .term-thumbnail { - float: left; - margin-bottom: 0; - width: 136px !important; - height: 136px !important; + .term-thumbnail { + margin-top: 1rem; + margin-bottom: 0rem; + } } +} +.tainacan-taxonomies-pagination-links { + text-align: end; } \ No newline at end of file diff --git a/src/functions.php b/src/functions.php index 65793a9..b9c23a2 100644 --- a/src/functions.php +++ b/src/functions.php @@ -395,37 +395,6 @@ function tainacan_hex2rgb( $color ) { ); } -function tainacan_collections_viewmode( $public_query_vars ) { - $public_query_vars[] = 'tainacan_collections_viewmode'; - return $public_query_vars; -} -add_filter( 'query_vars', 'tainacan_collections_viewmode' ); - -function tainacan_active( $selected, $current = true, $echo = true ) { - $return = $selected == $current ? 'active' : ''; - - if ( $echo ) { - echo $return; - } - - return $return; -} - -function tainacan_theme_collection_title( $title ) { - if ( is_post_type_archive( 'tainacan-collection' ) ) { - return __( 'Collections', 'tainacan-interface' ); - } - return $title; -} -add_filter( 'get_the_archive_title', 'tainacan_theme_collection_title' ); - -function tainacan_theme_collection_query( $query ) { - if ( $query->is_main_query() && $query->is_post_type_archive( 'tainacan-collection' ) ) { - $query->set( 'posts_per_page', 12 ); - } -} -add_action( 'pre_get_posts', 'tainacan_theme_collection_query' ); - /** * Render customizer colors to Gutenberg. */ @@ -466,5 +435,6 @@ add_action( 'enqueue_block_editor_assets', 'tainacan_editor_styles' ); require get_template_directory() . '/functions/customizer.php'; require get_template_directory() . '/functions/patterns.php'; require get_template_directory() . '/functions/single-functions.php'; +require get_template_directory() . '/functions/archive-functions.php'; require get_template_directory() . '/functions/class-tainacan-interface-collection-settings.php'; require get_template_directory() . '/functions/breadcrumb.php'; diff --git a/src/functions/archive-functions.php b/src/functions/archive-functions.php new file mode 100644 index 0000000..93f4f11 --- /dev/null +++ b/src/functions/archive-functions.php @@ -0,0 +1,107 @@ +is_main_query() && $query->is_post_type_archive( 'tainacan-collection' ) ) { + $query->set( 'posts_per_page', 12 ); + } +} +add_action( 'pre_get_posts', 'tainacan_theme_collection_query' ); + +/** + * Displays pagination using Tainacan Interface style. + */ +if ( ! function_exists( 'tainacan_pagination' ) ) : + function tainacan_pagination() { + global $wp_query; + $cur_posts = min( (int) $wp_query->get( 'posts_per_page' ), $wp_query->found_posts ); + $to_paged = max( (int) $wp_query->get( 'paged' ), 1 ); + $count_max = ( $to_paged - 1 ) * $cur_posts; ?> +
+
+ + post_count, $wp_query->found_posts ); ?> +
+
+ 2, + 'prev_text' => sprintf( + '%s', + '' + ), + 'next_text' => sprintf( + ' %s', + '' + ), + 'screen_reader_text' => ' ' + ) + ); ?> +
+
+ get_taxonomies_query_args(); + $current_total_terms = $total_terms; + $current_first_term_index = max(($current_args['termspaged'] - 1) * $current_args['perpage'] + 1, 1); + $current_last_term_index = min($current_args['termspaged'] * $current_args['perpage'], $current_total_terms); + ?> +
+
+ + +
+
+ array( + 'mid_size' => 2, + 'prev_text' => sprintf( + '%s', + '' + ), + 'next_text' => sprintf( + ' %s', + '' + ), + 'screen_reader_text' => ' ' + ) + ) + ); + ?> +
+
+ get( 'posts_per_page' ), $wp_query->found_posts ); - $to_paged = max( (int) $wp_query->get( 'paged' ), 1 ); - $count_max = ( $to_paged - 1 ) * $cur_posts; ?> -
-
- - post_count, $wp_query->found_posts ); ?> -
-
- 2, - 'prev_text' => sprintf( - '%s', - '' - ), - 'next_text' => sprintf( - ' %s', - '' - ), - 'screen_reader_text' => ' ' - ) - ); ?> -
-
- + +
-
    @@ -16,108 +17,68 @@
-
- - +
diff --git a/src/template-parts/loop-tainacan-terms-grid.php b/src/template-parts/loop-tainacan-terms-grid.php new file mode 100644 index 0000000..2967c57 --- /dev/null +++ b/src/template-parts/loop-tainacan-terms-grid.php @@ -0,0 +1,33 @@ + + + '
', + 'before_terms_list' => '', + 'before_term' => '
  • ', + 'after_term' => '
  • ', + 'before_term_thumbnail' => '
    ', + 'after_term_thumbnail' => '
    ', + 'before_term_name' => '

    ', + 'after_term_name' => '

    ', + 'thumbnails_size' => 'tainacan-medium', + 'hide_term_thumbnail_placeholder' => false, + 'hide_term_empty_name' => false, + 'trim_description_words' => 20 + )); + echo $taxonomy_terms_list['content']; + + $current_args = \Tainacan\Theme_Helper::get_instance()->get_taxonomies_query_args(); + $current_total_terms = $taxonomy_terms_list['total_terms']; + $current_first_term_index = max(($current_args['termspaged'] - 1) * $current_args['perpage'] + 1, 1); + $current_last_term_index = min($current_args['termspaged'] * $current_args['perpage'], $current_total_terms); + + // Terms pagination + tainacan_pagination_terms($current_total_terms); + } ?> + + + + \ No newline at end of file diff --git a/src/template-parts/loop-tainacan-terms-table.php b/src/template-parts/loop-tainacan-terms-table.php new file mode 100644 index 0000000..d351882 --- /dev/null +++ b/src/template-parts/loop-tainacan-terms-table.php @@ -0,0 +1,55 @@ + + + '
    ', + 'after_terms_list_container' => '
    ', + 'before_terms_list' => ' + + + + + + + + + + ', + 'after_terms_list' => '
    ' . __( 'Name', 'tainacan-interface' ) . '' . __( 'Description', 'tainacan-interface' ) . '' . __( 'Children', 'tainacan-interface' ) . '' . __( 'Items', 'tainacan-interface' ) . '
    ', + 'before_term' => '', + 'after_term' => '', + 'before_term_thumbnail' => '', + 'after_term_thumbnail' => '', + 'before_term_name' => '', + 'after_term_name' => '', + 'before_term_description' => '', + 'after_term_description' => '', + 'before_term_children_link' => '', + 'after_term_children_link' => '', + 'before_term_items_link' => '', + 'after_term_items_link' => '', + 'hide_term_empty_name' => false, + 'hide_term_empty_description' => false, + 'hide_term_empty_children_link' => false, + 'hide_term_empty_items_link' => false, + 'thumbnails_size' => 'tainacan-medium', + 'hide_term_thumbnail_placeholder' => false, + 'hide_term_description' => false, + 'trim_description_words' => 32 + )); + echo $taxonomy_terms_list['content']; + + $current_args = \Tainacan\Theme_Helper::get_instance()->get_taxonomies_query_args(); + $current_total_terms = $taxonomy_terms_list['total_terms']; + $current_first_term_index = max(($current_args['termspaged'] - 1) * $current_args['perpage'] + 1, 1); + $current_last_term_index = min($current_args['termspaged'] * $current_args['perpage'], $current_total_terms); + + } ?> + + + + + + + \ No newline at end of file diff --git a/src/template-parts/loop-tainacan-terms.php b/src/template-parts/loop-tainacan-terms.php new file mode 100644 index 0000000..e165577 --- /dev/null +++ b/src/template-parts/loop-tainacan-terms.php @@ -0,0 +1,33 @@ + + + '
    ', + 'before_terms_list' => '
      ', + 'after_terms_list' => '
    ', + 'before_term' => '
  • ', + 'after_term' => '
  • ', + 'before_term_thumbnail' => '
    ', + 'after_term_thumbnail' => '
    ', + 'before_term_description' => '

    ', + 'thumbnails_size' => 'tainacan-medium', + 'hide_term_thumbnail_placeholder' => false, + 'hide_term_description' => false, + 'hide_term_empty_name' => false, + 'trim_description_words' => 20 + )); + echo $taxonomy_terms_list['content']; + + $current_args = \Tainacan\Theme_Helper::get_instance()->get_taxonomies_query_args(); + $current_total_terms = $taxonomy_terms_list['total_terms']; + $current_first_term_index = max(($current_args['termspaged'] - 1) * $current_args['perpage'] + 1, 1); + $current_last_term_index = min($current_args['termspaged'] * $current_args['perpage'], $current_total_terms); + + // Terms pagination + tainacan_pagination_terms($current_total_terms); + } ?> + + + + \ No newline at end of file