Add latest chapters card footer filter

This commit is contained in:
Tetrakern 2023-09-10 18:48:20 +02:00
parent 894bea4dba
commit f23e781400
2 changed files with 58 additions and 14 deletions

View File

@ -662,6 +662,23 @@ Filters the query arguments in the `fictioneer_blog` shortcode.
---
### `apply_filters( 'fictioneer_filter_shortcode_latest_chapters_card_footer', $footer_items, $post, $story, $args )`
Filters the intermediate output array in the `_latest-chapters.php` partial before it is imploded and rendered. Contains statistics with icons such as the number of chapters, words, dates, and so forth.
**$footer_items:**
* $words (string) HTML for the total word count.
* $publish_date (string) Conditional. HTML for the publish date.
* $modified_date (string) Conditional. HTML for the modified date.
* $comments (string) HTML for the number of comments.
* $status (string|null) Conditional. HTML for the story status.
**Parameters**
* $post (WP_Post) The post object.
* $story (array|null) Optional. Collection of story post data.
* $args (array) Arguments passed to the partial.
---
### `apply_filters( 'fictioneer_filter_shortcode_latest_chapters_query_args', $query_args, $args )`
Filters the query arguments in the `fictioneer_latest_chapters` shortcode. The optional taxonomy arrays can include categories, tags, fandoms, genres, and characters.

View File

@ -47,7 +47,9 @@ $query_args = array(
);
// Parameter for author?
if ( isset( $args['author'] ) && $args['author'] ) $query_args['author_name'] = $args['author'];
if ( isset( $args['author'] ) && $args['author'] ) {
$query_args['author_name'] = $args['author'];
}
// Taxonomies?
if ( ! empty( $args['taxonomies'] ) ) {
@ -102,7 +104,9 @@ $entries = fictioneer_shortcode_query( $query_args );
}
// Count actually rendered cards to account for buffer
if ( ++$card_counter > $args['count'] ) break;
if ( ++$card_counter > $args['count'] ) {
break;
}
?>
<li class="card _small">
@ -156,23 +160,46 @@ $entries = fictioneer_shortcode_query( $query_args );
<?php if ( ! $args['simple'] ) : ?>
<div class="card__footer _small">
<div class="card__footer-box _left text-overflow-ellipsis">
<div class="card__footer-box _left text-overflow-ellipsis"><?php
<i class="card-footer-icon fa-solid fa-font" title="<?php esc_attr_e( 'Words', 'fictioneer' ) ?>"></i>
<?php echo fictioneer_shorten_number( get_post_meta( $post->ID, '_word_count', true ) ); ?>
// Build footer items
$footer_items = [];
<i class="card-footer-icon fa-solid fa-clock" title="<?php esc_attr_e( 'Published', 'fictioneer' ) ?>"></i>
<?php echo get_the_date( FICTIONEER_LATEST_CHAPTERS_FOOTER_DATE ); ?>
$footer_items['words'] = '<i class="card-footer-icon fa-solid fa-font" title="' .
esc_attr__( 'Words', 'fictioneer' ) . '"></i> ' .
fictioneer_shorten_number( get_post_meta( $post->ID, '_word_count', true ) );
<i class="card-footer-icon fa-solid fa-message" title="<?php esc_attr_e( 'Comments', 'fictioneer' ) ?>"></i>
<?php echo get_comments_number(); ?>
if ( $args['orderby'] == 'modified' ) {
$footer_items['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 );
} else {
$footer_items['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 );
}
<?php if ( $story ) : ?>
<i class="card-footer-icon <?php echo $story['icon']; ?>"></i>
<?php echo fcntr( $story['status'] ); ?>
<?php endif; ?>
$footer_items['comments'] = '<i class="card-footer-icon fa-solid fa-message" title="' .
esc_attr__( 'Comments', 'fictioneer' ) . '"></i> ' . get_comments_number();
</div>
if ( $story ) {
$footer_items['status'] = '<i class="card-footer-icon ' . $story['icon'] . '"></i> ' .
fcntr( $story['status'] );
}
// Filer footer items
$footer_items = apply_filters(
'fictioneer_filter_shortcode_latest_chapters_card_footer',
$footer_items,
$post,
$args,
$story
);
// Implode and render footer items
echo implode( ' ', $footer_items );
?></div>
<?php if ( ! empty( $chapter_rating ) ) : ?>
<div class="card__footer-box _right rating-letter-label tooltipped" data-tooltip="<?php echo fcntr( $chapter_rating, true ) ?>">