From 8034df26147957423c875a51f0b8403efb66bb85 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Wed, 29 May 2024 00:01:31 +0200 Subject: [PATCH] Add words and date params to Latest Updates shortcode --- DOCUMENTATION.md | 2 ++ includes/functions/_setup-shortcodes.php | 4 +++ partials/_latest-updates-compact.php | 26 +++++++++++++++-- partials/_latest-updates.php | 36 +++++++++++++++++++----- 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index b1aca894..ba263262 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -1043,6 +1043,8 @@ Renders a multi-column grid of small cards, showing the latest four updated stor * **thumbnail:** Whether to show the thumbnail/cover image. Default `true` (Customizer setting). * **lightbox:** Whether clicking on the thumbnail/cover image opens the lightbox or post link. Default `true`. * **aspect_ratio:** CSS [aspect-ratio](https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio) value for the image (X/Y; vertical only). Default `3/1`. +* **words:** Whether to show the word count of chapter items. Default `true`. +* **date:** Whether to show the date of chapter items. Default `true`. * **class:** Additional CSS classes, separated by whitespace. ``` diff --git a/includes/functions/_setup-shortcodes.php b/includes/functions/_setup-shortcodes.php index 505b01e4..cc413c94 100644 --- a/includes/functions/_setup-shortcodes.php +++ b/includes/functions/_setup-shortcodes.php @@ -201,6 +201,8 @@ function fictioneer_get_default_shortcode_args( $attr, $def_count = -1 ) { 'aspect_ratio' => sanitize_css_aspect_ratio( $attr['aspect_ratio'] ?? '' ), 'thumbnail' => filter_var( $attr['thumbnail'] ?? $thumbnail_default, FILTER_VALIDATE_BOOLEAN ), 'lightbox' => filter_var( $attr['lightbox'] ?? 1, FILTER_VALIDATE_BOOLEAN ), + 'words' => filter_var( $attr['words'] ?? 1, FILTER_VALIDATE_BOOLEAN ), + 'date' => filter_var( $attr['date'] ?? 1, FILTER_VALIDATE_BOOLEAN ), 'classes' => esc_attr( wp_strip_all_tags( $attr['class'] ?? '' ) ) ); @@ -628,6 +630,8 @@ add_shortcode( 'fictioneer_story_cards', 'fictioneer_shortcode_latest_stories' ) * @param string|null $attr['aspect_ratio'] Optional. Aspect ratio for the image. Only with vertical. * @param string|null $attr['lightbox'] Optional. Whether the thumbnail is opened in the lightbox. Default true. * @param string|null $attr['thumbnail'] Optional. Whether to show the thumbnail. Default true (Customizer). + * @param string|null $attr['words'] Optional. Whether to show the word count of chapter items. Default true. + * @param string|null $attr['date'] Optional. Whether to show the date of chapter items. Default true. * @param string|null $attr['class'] Optional. Additional CSS classes, separated by whitespace. * * @return string The captured shortcode HTML. diff --git a/partials/_latest-updates-compact.php b/partials/_latest-updates-compact.php index ed7a338d..2b97e481 100644 --- a/partials/_latest-updates-compact.php +++ b/partials/_latest-updates-compact.php @@ -28,6 +28,8 @@ * @internal $args['aspect_ratio'] Aspect ratio for the image. Only with vertical. * @internal $args['lightbox'] Whether the image is opened in the lightbox. Default true. * @internal $args['thumbnail'] Whether the image is rendered. Default true (Customizer). + * @internal $args['words'] Whether to show the word count of chapter items. Default true. + * @internal $args['date'] Whether to show the date of chapter items. Default true. * @internal $args['classes'] String of additional CSS classes. Default empty. */ @@ -160,6 +162,14 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); $card_classes[] = '_seamless'; } + if ( ! $args['words'] ) { + $card_classes[] = '_no-chapter-words'; + } + + if ( ! $args['date'] ) { + $card_classes[] = '_no-chapter-dates'; + } + // Search for viable chapters... $search_list = array_reverse( $story['chapter_ids'] ); @@ -285,9 +295,19 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
ID ) ); - echo ' • '; - echo get_the_date( FICTIONEER_LATEST_UPDATES_LI_DATE, $chapter->ID ) + if ( $args['words'] ) { + echo '' . + fictioneer_shorten_number( fictioneer_get_word_count( $chapter->ID ) ) . ''; + } + + if ( $args['words'] && $args['date'] ) { + echo ' • '; + } + + if ( $args['date'] ) { + echo '' . + get_the_date( FICTIONEER_LATEST_UPDATES_LI_DATE, $chapter->ID ) . ''; + } ?>
diff --git a/partials/_latest-updates.php b/partials/_latest-updates.php index b66e125d..284b6586 100644 --- a/partials/_latest-updates.php +++ b/partials/_latest-updates.php @@ -30,6 +30,8 @@ * @internal $args['aspect_ratio'] Aspect ratio for the image. Only with vertical. * @internal $args['lightbox'] Whether the image is opened in the lightbox. Default true. * @internal $args['thumbnail'] Whether the image is rendered. Default true (Customizer). + * @internal $args['words'] Whether to show the word count of chapter items. Default true. + * @internal $args['date'] Whether to show the date of chapter items. Default true. * @internal $args['classes'] String of additional CSS classes. Default empty. */ @@ -164,6 +166,14 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); $card_classes[] = '_seamless'; } + if ( ! $args['words'] ) { + $card_classes[] = '_no-chapter-words'; + } + + if ( ! $args['date'] ) { + $card_classes[] = '_no-chapter-dates'; + } + // Search for viable chapters... $search_list = array_reverse( $story['chapter_ids'] ); @@ -291,13 +301,25 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' ); echo $chapter_title; ?> -
- ID ) ); - echo ' • '; - echo get_the_date( FICTIONEER_LATEST_UPDATES_LI_DATE, $chapter->ID ) - ?> -
+ +
+ ' . + fictioneer_shorten_number( fictioneer_get_word_count( $chapter->ID ) ) . ''; + } + + if ( $args['words'] && $args['date'] ) { + echo ' • '; + } + + if ( $args['date'] ) { + echo '' . + get_the_date( FICTIONEER_LATEST_UPDATES_LI_DATE, $chapter->ID ) . ''; + } + ?> +
+