Add footer_* params to Latest Chapters shortcode

This commit is contained in:
Tetrakern 2024-08-18 21:34:32 +02:00
parent b69d3086ce
commit 4384ecc3c0
7 changed files with 73 additions and 12 deletions

View File

@ -997,6 +997,11 @@ Renders a multi-column grid of small cards, showing the latest four chapters ord
* **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`.
* **infobox:** Whether to show the info box and toggle on compact versions. Default `true`.
* **footer_words:** Whether to show the chapter word count. Default `true`.
* **footer_date:** Whether to show the chapter date. Default `true`.
* **footer_comments:** Whether to show the chapter comment count. Default `true`.
* **footer_status:** Whether to show the chapter story status. Default `true`.
* **footer_rating:** Whether to show the chapter age rating. 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`.
* **class:** Additional CSS classes, separated by whitespace.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -203,6 +203,11 @@ function fictioneer_get_default_shortcode_args( $attr, $def_count = -1 ) {
'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 ),
'footer_words' => filter_var( $attr['footer_words'] ?? 1, FILTER_VALIDATE_BOOLEAN ),
'footer_date' => filter_var( $attr['footer_date'] ?? 1, FILTER_VALIDATE_BOOLEAN ),
'footer_comments' => filter_var( $attr['footer_comments'] ?? 1, FILTER_VALIDATE_BOOLEAN ),
'footer_status' => filter_var( $attr['footer_status'] ?? 1, FILTER_VALIDATE_BOOLEAN ),
'footer_rating' => filter_var( $attr['footer_rating'] ?? 1, FILTER_VALIDATE_BOOLEAN ),
'classes' => esc_attr( wp_strip_all_tags( $attr['class'] ?? '' ) ),
'infobox' => filter_var( $attr['infobox'] ?? 1, FILTER_VALIDATE_BOOLEAN ),
'source' => filter_var( $attr['source'] ?? 1, FILTER_VALIDATE_BOOLEAN )

View File

@ -30,6 +30,11 @@
* @internal $args['thumbnail'] Whether the image is rendered. Default true (Customizer).
* @internal $args['classes'] String of additional CSS classes. Default empty.
* @internal $args['infobox'] Whether to show the info box and toggle.
* @internal $args['footer_words'] Whether to show the chapter word count. Default true.
* @internal $args['footer_date'] Whether to show the chapter date. Default true.
* @internal $args['footer_comments'] Whether to show the chapter comment count. Default true.
* @internal $args['footer_status'] Whether to show the chapter story status. Default true.
* @internal $args['footer_rating'] Whether to show the chapter age rating. Default true.
*/
@ -155,6 +160,14 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
$card_classes[] = '_seamless';
}
if ( ! $args['footer_words'] ) {
$card_classes[] = '_no-footer-words';
}
if ( ! $args['footer_date'] ) {
$card_classes[] = '_no-footer-date';
}
// Count actually rendered cards to account for buffer
if ( ++$card_counter > $args['count'] ) {
break;
@ -238,14 +251,21 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
</div>
<div class="card__words-on-date text-overflow-ellipsis">
<?php
if ( $words > 0 ) {
if ( $words > 0 && $args['footer_words'] && $args['footer_date'] ) {
printf(
_x( '%1$s Words on %2$s', 'Small card: {n} Words on {Date}.', 'fictioneer' ),
fictioneer_shorten_number( fictioneer_get_word_count( $post_id ) ),
get_the_time( FICTIONEER_LATEST_CHAPTERS_FOOTER_DATE )
);
} else {
the_time( FICTIONEER_LATEST_CHAPTERS_FOOTER_DATE );
if ( $words > 0 && $args['footer_words'] ) {
printf(
_x( '%1$s Words', 'Small card: {n} Words.', 'fictioneer' ),
fictioneer_shorten_number( fictioneer_get_word_count( $post_id ) )
);
} elseif ( $args['footer_date'] ) {
the_time( FICTIONEER_LATEST_CHAPTERS_FOOTER_DATE );
}
}
?>
</div>

View File

@ -30,6 +30,11 @@
* @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['footer_words'] Whether to show the chapter word count. Default true.
* @internal $args['footer_date'] Whether to show the chapter date. Default true.
* @internal $args['footer_comments'] Whether to show the chapter comment count. Default true.
* @internal $args['footer_status'] Whether to show the chapter story status. Default true.
* @internal $args['footer_rating'] Whether to show the chapter age rating. Default true.
* @internal $args['classes'] String of additional CSS classes. Default empty.
*/
@ -161,6 +166,14 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
$card_classes[] = '_seamless';
}
if ( ! $args['footer_words'] ) {
$card_classes[] = '_no-footer-words';
}
if ( ! $args['footer_date'] ) {
$card_classes[] = '_no-footer-date';
}
// Truncate factor
$truncate_factor = $args['vertical'] ? '_4-4' : '_cq-3-4';
@ -273,19 +286,23 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
// Build footer items
$footer_items = [];
if ( $words > 0 ) {
if ( $words > 0 && $args['footer_words'] ) {
$footer_items['words'] = '<span class="card__footer-words"><i class="card-footer-icon fa-solid fa-font" title="' . esc_attr__( 'Words', 'fictioneer' ) . '"></i> ' . fictioneer_shorten_number( fictioneer_get_word_count( $post_id ) ) . '</span>';
}
if ( $args['orderby'] === 'modified' ) {
$footer_items['modified_date'] = '<span class="card__footer-modified-date"><i class="card-footer-icon fa-regular fa-clock" title="' . esc_attr__( 'Last Updated', 'fictioneer' ) . '"></i> ' . get_the_modified_date( FICTIONEER_LATEST_CHAPTERS_FOOTER_DATE, $post ) . '</span>';
} else {
$footer_items['publish_date'] = '<span class="card__footer-publish-date"><i class="card-footer-icon fa-solid fa-clock" title="' . esc_attr__( 'Published', 'fictioneer' ) . '"></i> ' . get_the_date( FICTIONEER_LATEST_CHAPTERS_FOOTER_DATE, $post ) . '</span>';
if ( $args['footer_date'] ) {
if ( $args['orderby'] === 'modified' ) {
$footer_items['modified_date'] = '<span class="card__footer-modified-date"><i class="card-footer-icon fa-regular fa-clock" title="' . esc_attr__( 'Last Updated', 'fictioneer' ) . '"></i> ' . get_the_modified_date( FICTIONEER_LATEST_CHAPTERS_FOOTER_DATE, $post ) . '</span>';
} else {
$footer_items['publish_date'] = '<span class="card__footer-publish-date"><i class="card-footer-icon fa-solid fa-clock" title="' . esc_attr__( 'Published', 'fictioneer' ) . '"></i> ' . get_the_date( FICTIONEER_LATEST_CHAPTERS_FOOTER_DATE, $post ) . '</span>';
}
}
$footer_items['comments'] = '<span class="card__footer-comments"><i class="card-footer-icon fa-solid fa-message" title="' . esc_attr__( 'Comments', 'fictioneer' ) . '"></i> ' . get_comments_number() . '</span>';
if ( $args['footer_comments'] ) {
$footer_items['comments'] = '<span class="card__footer-comments"><i class="card-footer-icon fa-solid fa-message" title="' . esc_attr__( 'Comments', 'fictioneer' ) . '"></i> ' . get_comments_number() . '</span>';
}
if ( $story ) {
if ( $story && $args['footer_status'] ) {
$footer_items['status'] = '<span class="card__footer-status"><i class="card-footer-icon ' . $story['icon'] . '"></i> ' . fcntr( $story['status'] ) . '</span>';
}
@ -303,7 +320,7 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
?></div>
<?php if ( ! empty( $chapter_rating ) ) : ?>
<?php if ( ! empty( $chapter_rating ) && $args['footer_rating'] ) : ?>
<div class="card__footer-box _right rating-letter-label tooltipped" data-tooltip="<?php echo fcntr( $chapter_rating, true ); ?>">
<?php echo fcntr( $chapter_rating[0] ); ?>
</div>

View File

@ -628,6 +628,20 @@
}
}
&._compact._chapter._no-footer-words._no-footer-date {
.card__title {
margin-bottom: 0;
}
.card__content {
margin-bottom: var(--this-spacing);
> div {
display: none;
}
}
}
&._vertical {
.cell-img {
display: block;