2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Partial: Latest Chapters
|
|
|
|
*
|
|
|
|
* Renders the (buffered) HTML for the [fictioneer_latest_chapters] shortcode.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Fictioneer
|
|
|
|
* @since 4.0
|
|
|
|
*
|
2023-08-17 21:46:17 +02:00
|
|
|
* @internal $args['count'] Number of posts provided by the shortcode.
|
|
|
|
* @internal $args['author'] Author provided by the shortcode.
|
|
|
|
* @internal $args['order'] Order of posts. Default 'desc'.
|
|
|
|
* @internal $args['orderby'] Sorting of posts. Default 'date'.
|
|
|
|
* @internal $args['spoiler'] Whether to obscure or show chapter excerpt.
|
|
|
|
* @internal $args['source'] Whether to show author and story.
|
|
|
|
* @internal $args['post_ids'] Array of post IDs. Default empty.
|
|
|
|
* @internal $args['excluded_cats'] Array of category IDs to exclude. Default empty.
|
|
|
|
* @internal $args['excluded_tags'] Array of tag IDs to exclude. Default empty.
|
|
|
|
* @internal $args['taxonomies'] Array of taxonomy arrays. Default empty.
|
|
|
|
* @internal $args['relation'] Relationship between taxonomies.
|
|
|
|
* @internal $args['simple'] Whether to show the simple variant.
|
|
|
|
* @internal $args['class'] Additional classes.
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
?>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
2023-08-20 20:21:48 +02:00
|
|
|
// No direct access!
|
|
|
|
defined( 'ABSPATH' ) OR exit;
|
|
|
|
|
2023-08-17 21:46:17 +02:00
|
|
|
// Setup
|
|
|
|
$card_counter = 0;
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// Prepare query
|
|
|
|
$query_args = array(
|
|
|
|
'post_type' => 'fcn_chapter',
|
2023-03-09 02:03:09 +01:00
|
|
|
'post_status' => 'publish',
|
2023-08-17 01:32:02 +02:00
|
|
|
'post__in' => $args['post_ids'], // May be empty!
|
2023-01-21 01:31:34 +01:00
|
|
|
'orderby' => $args['orderby'] ?? 'date',
|
|
|
|
'order' => $args['order'] ?? 'desc',
|
2023-08-17 21:46:17 +02:00
|
|
|
'posts_per_page' => $args['count'] + 8, // Little buffer in case of unpublished parent story
|
2023-01-21 01:31:34 +01:00
|
|
|
'meta_key' => 'fictioneer_chapter_hidden',
|
|
|
|
'meta_value' => 0,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'update_post_term_cache' => false
|
|
|
|
);
|
|
|
|
|
|
|
|
// Parameter for author?
|
|
|
|
if ( isset( $args['author'] ) && $args['author'] ) $query_args['author_name'] = $args['author'];
|
|
|
|
|
2023-03-08 23:24:41 +01:00
|
|
|
// Taxonomies?
|
|
|
|
if ( ! empty( $args['taxonomies'] ) ) {
|
|
|
|
$query_args['tax_query'] = fictioneer_get_shortcode_tax_query( $args );
|
|
|
|
}
|
|
|
|
|
2023-03-10 17:01:42 +01:00
|
|
|
// Excluded tags?
|
|
|
|
if ( ! empty( $args['excluded_tags'] ) ) {
|
|
|
|
$query_args['tag__not_in'] = $args['excluded_tags'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Excluded categories?
|
|
|
|
if ( ! empty( $args['excluded_cats'] ) ) {
|
|
|
|
$query_args['category__not_in'] = $args['excluded_cats'];
|
|
|
|
}
|
|
|
|
|
2023-03-09 02:04:21 +01:00
|
|
|
// Apply filters
|
2023-03-10 15:20:48 +01:00
|
|
|
$query_args = apply_filters( 'fictioneer_filter_shortcode_latest_chapters_query_args', $query_args, $args );
|
2023-03-09 02:04:21 +01:00
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// Query chapters
|
2023-08-03 13:17:32 +02:00
|
|
|
$entries = fictioneer_shortcode_query( $query_args );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
?>
|
|
|
|
|
2023-01-27 01:23:02 +01:00
|
|
|
<section class="small-card-block latest-chapters <?php echo implode( ' ', $args['classes'] ); ?>">
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php if ( $entries->have_posts() ) : ?>
|
|
|
|
|
|
|
|
<ul class="two-columns _collapse-on-mobile">
|
|
|
|
<?php while ( $entries->have_posts() ) : $entries->the_post(); ?>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
// Setup
|
2023-08-17 21:46:17 +02:00
|
|
|
$story_id = fictioneer_get_field( 'fictioneer_chapter_story' );
|
|
|
|
|
|
|
|
if ( get_post_status( $story_id ) !== 'publish' ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
$title = fictioneer_get_safe_title( get_the_ID() );
|
|
|
|
$chapter_rating = fictioneer_get_field( 'fictioneer_chapter_rating' );
|
2023-08-05 18:31:39 +02:00
|
|
|
$story = $story_id ? fictioneer_get_story_data( $story_id, false ) : false; // Does not refresh comment count!
|
2023-01-21 01:31:34 +01:00
|
|
|
$text_icon = fictioneer_get_field( 'fictioneer_chapter_text_icon' );
|
|
|
|
|
|
|
|
// Chapter images
|
|
|
|
$thumbnail_full = get_the_post_thumbnail_url( $post, 'full' );
|
|
|
|
$thumbnail_snippet = get_the_post_thumbnail( $post, 'snippet', ['class' => 'no-auto-lightbox'] );
|
|
|
|
|
|
|
|
// Story images
|
|
|
|
if ( ! $thumbnail_full && $story ) {
|
|
|
|
$thumbnail_full = get_the_post_thumbnail_url( $story_id, 'full' );
|
|
|
|
$thumbnail_snippet = get_the_post_thumbnail( $story_id, 'snippet', ['class' => 'no-auto-lightbox']);
|
|
|
|
}
|
2023-08-17 21:46:17 +02:00
|
|
|
|
|
|
|
// Count actually rendered cards to account for buffer
|
|
|
|
if ( ++$card_counter > $args['count'] ) break;
|
2023-01-21 01:31:34 +01:00
|
|
|
?>
|
|
|
|
|
|
|
|
<li class="card _small">
|
|
|
|
<div class="card__body polygon">
|
|
|
|
|
|
|
|
<div class="card__main _grid _small">
|
|
|
|
|
|
|
|
<?php if ( $thumbnail_full ) : ?>
|
|
|
|
<a href="<?php echo $thumbnail_full; ?>" title="<?php echo esc_attr( sprintf( __( '%s Thumbnail', 'fictioneer' ), $title ) ); ?>" class="card__image cell-img" <?php echo fictioneer_get_lightbox_attribute(); ?>><?php echo $thumbnail_snippet ?></a>
|
|
|
|
<?php elseif ( ! empty( $text_icon ) ) : ?>
|
|
|
|
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( $title ) ?>" class="card__text-icon _small cell-img"><span class="text-icon"><?php echo $text_icon; ?></span></a>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
2023-02-09 10:44:04 +01:00
|
|
|
<h3 class="card__title _small cell-title"><a href="<?php the_permalink(); ?>" class="truncate _1-1"><?php
|
2023-01-21 01:31:34 +01:00
|
|
|
$list_title = fictioneer_get_field( 'fictioneer_chapter_list_title' );
|
|
|
|
echo $list_title ? wp_strip_all_tags( $list_title ) : $title;
|
|
|
|
?></a></h3>
|
|
|
|
|
|
|
|
<div class="card__content _small cell-desc">
|
2023-06-17 23:21:24 +02:00
|
|
|
<div class="truncate _3-3 <?php if ( ! $args['spoiler'] ) echo '_obfuscated'; ?>" data-obfuscation-target>
|
2023-06-04 14:02:12 +02:00
|
|
|
<?php if ( get_option( 'fictioneer_show_authors' ) && $args['source'] ) : ?>
|
|
|
|
<span class="card__by-author"><?php
|
|
|
|
printf( _x( 'by %s', 'Small card: by {Author}.', 'fictioneer' ), fictioneer_get_author_node() );
|
|
|
|
?></span>
|
|
|
|
<?php endif; ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
|
|
|
if ( $story && $args['source'] ) {
|
|
|
|
printf(
|
2023-06-04 14:02:12 +02:00
|
|
|
_x( 'in <a href="%1$s" class="bold-link">%2$s</a>', 'Small card: in {Link to Story}.', 'fictioneer' ),
|
2023-01-21 01:31:34 +01:00
|
|
|
get_permalink( $story_id ),
|
|
|
|
mb_strimwidth( fictioneer_get_safe_title( $story_id ), 0, 24, '…' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$excerpt = fictioneer_get_forced_excerpt( $post );
|
2023-02-09 09:08:19 +01:00
|
|
|
$spoiler_note = str_repeat( _x( '· ', 'Chapter preview obfuscation character.', 'fictioneer' ), intval( strlen( $excerpt ) ) );
|
2023-01-21 01:31:34 +01:00
|
|
|
?>
|
|
|
|
<?php if ( ! $args['spoiler'] ) : ?>
|
2023-06-18 03:28:44 +02:00
|
|
|
<span data-click="toggle-obfuscation" tabindex="0">
|
2023-01-21 01:31:34 +01:00
|
|
|
<span class="obfuscated"> <?php echo $spoiler_note; ?></span>
|
2023-06-04 14:02:12 +02:00
|
|
|
<span class="clean">— <?php echo $excerpt; ?></span>
|
2023-01-21 01:31:34 +01:00
|
|
|
</span>
|
|
|
|
<?php else : ?>
|
2023-06-04 14:02:12 +02:00
|
|
|
<span><span class="clean">— <?php echo $excerpt; ?></span></span>
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php if ( ! $args['simple'] ) : ?>
|
|
|
|
<div class="card__footer _small">
|
|
|
|
|
2023-08-30 10:42:10 +02:00
|
|
|
<div class="card__footer-box _left text-overflow-ellipsis">
|
2023-06-04 22:17:42 +02:00
|
|
|
|
2023-08-30 10:42:10 +02:00
|
|
|
<i class="card-footer-icon fa-solid fa-font" title="<?php esc_attr_e( 'Words', 'fictioneer' ) ?>"></i>
|
2023-06-04 22:17:42 +02:00
|
|
|
<?php echo fictioneer_shorten_number( get_post_meta( $post->ID, '_word_count', true ) ); ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2023-08-30 10:42:10 +02:00
|
|
|
<i class="card-footer-icon fa-solid fa-clock" title="<?php esc_attr_e( 'Published', 'fictioneer' ) ?>"></i>
|
2023-06-06 22:01:29 +02:00
|
|
|
<?php echo get_the_date( FICTIONEER_LATEST_CHAPTERS_FOOTER_DATE ); ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2023-08-30 10:42:10 +02:00
|
|
|
<i class="card-footer-icon fa-solid fa-message" title="<?php esc_attr_e( 'Comments', 'fictioneer' ) ?>"></i>
|
2023-06-04 22:17:42 +02:00
|
|
|
<?php echo get_comments_number(); ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<?php if ( $story ) : ?>
|
2023-08-30 10:42:10 +02:00
|
|
|
<i class="card-footer-icon <?php echo $story['icon']; ?>"></i>
|
2023-06-04 22:17:42 +02:00
|
|
|
<?php echo fcntr( $story['status'] ); ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php endif; ?>
|
2023-06-04 22:17:42 +02:00
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php if ( ! empty( $chapter_rating ) ) : ?>
|
2023-08-30 10:42:10 +02:00
|
|
|
<div class="card__footer-box _right rating-letter-label tooltipped" data-tooltip="<?php echo fcntr( $chapter_rating, true ) ?>">
|
2023-06-04 22:17:42 +02:00
|
|
|
<?php echo fcntr( $chapter_rating[0] ); ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<?php endwhile; ?>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
|
|
|
<div class="no-results"><?php _e( 'No chapters have been published yet.', 'fictioneer' ); ?></div>
|
|
|
|
|
|
|
|
<?php endif; wp_reset_postdata(); ?>
|
|
|
|
</section>
|