fictioneer/partials/_latest-chapters-compact.php

212 lines
7.8 KiB
PHP
Raw Normal View History

2023-01-21 01:31:34 +01:00
<?php
/**
* Partial: Latest Chapters Compact
*
* Renders the (buffered) HTML for the [fictioneer_latest_chapters type="compact"] shortcode.
*
* @package WordPress
* @subpackage Fictioneer
* @since 4.0
2023-01-21 01:31:34 +01: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.
2023-09-16 23:41:30 +02:00
* @internal $args['author_ids'] Array of author IDs. Default empty.
* @internal $args['excluded_authors'] Array of author IDs to exclude. 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['ignore_protected'] Whether to ignore protected posts. Default false.
* @internal $args['taxonomies'] Array of taxonomy arrays. Default empty.
* @internal $args['relation'] Relationship between taxonomies.
2023-09-15 22:42:34 +02:00
* @internal $args['classes'] String of additional CSS classes. Default empty.
2023-01-21 01:31:34 +01:00
*/
?>
<?php
// No direct access!
defined( 'ABSPATH' ) OR exit;
// Setup
$card_counter = 0;
2023-01-21 01:31:34 +01:00
// Prepare query
$query_args = array(
2023-09-15 14:00:44 +02:00
'fictioneer_query_name' => 'latest_chapters_compact',
2023-01-21 01:31:34 +01:00
'post_type' => 'fcn_chapter',
2023-03-09 02:03:09 +01:00
'post_status' => 'publish',
'post__in' => $args['post_ids'], // May be empty!
'order' => $args['order'],
'orderby' => $args['orderby'],
'posts_per_page' => $args['count'] + 8, // Little buffer in case of unpublished parent story
2023-01-21 01:31:34 +01:00
'no_found_rows' => true,
'update_post_term_cache' => false,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'fictioneer_chapter_hidden',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'fictioneer_chapter_hidden',
'value' => 0,
'compare' => '='
)
)
2023-01-21 01:31:34 +01:00
);
// Author?
2023-09-17 01:28:14 +02:00
if ( ! empty( $args['author'] ) ) {
$query_args['author_name'] = $args['author'];
}
// Author IDs?
if ( ! empty( $args['author_ids'] ) ) {
$query_args['author__in'] = $args['author_ids'];
}
2023-01-21 01:31:34 +01:00
2023-03-08 23:24:41 +01:00
// Taxonomies?
if ( ! empty( $args['taxonomies'] ) ) {
$query_args['tax_query'] = fictioneer_get_shortcode_tax_query( $args );
}
// 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'];
}
// Excluded authors?
if ( ! empty( $args['excluded_authors'] ) ) {
$query_args['author__not_in'] = $args['excluded_authors'];
}
// Ignore protected?
if ( $args['ignore_protected'] ) {
add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
}
// 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-01-21 01:31:34 +01:00
// Query chapters
$entries = fictioneer_shortcode_query( $query_args );
2023-01-21 01:31:34 +01:00
// Remove temporary filters
remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
2023-01-21 01:31:34 +01:00
?>
2023-09-15 22:42:34 +02:00
<section class="small-card-block latest-chapters _compact <?php echo $args['classes']; ?>">
2023-01-21 01:31:34 +01:00
<?php if ( $entries->have_posts() ) : ?>
<ul class="grid-columns _collapse-on-mobile">
2023-01-21 01:31:34 +01:00
<?php while ( $entries->have_posts() ) : $entries->the_post(); ?>
<?php
// Setup
2023-12-02 00:00:13 +01:00
$story_id = get_post_meta( $post->ID, 'fictioneer_chapter_story', true );
if ( get_post_status( $story_id ) !== 'publish' ) {
continue;
}
2023-12-02 00:00:13 +01:00
$title = fictioneer_get_safe_title( $post->ID );
$story = $story_id ? fictioneer_get_story_data( $story_id, false ) : false; // Does not refresh comment count!
2023-12-02 00:00:13 +01:00
$text_icon = get_post_meta( $post->ID, 'fictioneer_chapter_text_icon', true );
2023-01-21 01:31:34 +01:00
// 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']);
}
// Count actually rendered cards to account for buffer
2023-11-13 11:05:05 +01:00
if ( ++$card_counter > $args['count'] ) {
break;
}
2023-01-21 01:31:34 +01:00
?>
<li class="card watch-last-clicked _small _info">
2023-01-21 01:31:34 +01:00
<div class="card__body polygon">
2023-06-11 19:24:16 +02:00
<button class="card__info-toggle toggle-last-clicked" aria-label="<?php esc_attr_e( 'Open info box', 'fictioneer' ); ?>"><i class="fa-solid fa-chevron-down"></i></button>
2023-01-21 01:31:34 +01:00
<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 ) ) : ?>
2023-09-16 14:25:26 +02:00
<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>
2023-01-21 01:31:34 +01:00
<?php endif; ?>
<h3 class="card__title _small cell-title"><a href="<?php the_permalink(); ?>" class="truncate _1-1"><?php
2023-12-02 00:00:13 +01:00
$list_title = get_post_meta( $post->ID, 'fictioneer_chapter_list_title', true );
2023-10-08 15:28:23 +02:00
$list_title = trim( wp_strip_all_tags( $list_title ) );
2024-01-18 21:44:29 +01:00
if ( ! empty( $post->post_password ) ) {
echo '<i class="fa-solid fa-lock protected-icon"></i> ';
}
2023-10-08 15:28:23 +02:00
echo $list_title ? $list_title : $title;
2023-01-21 01:31:34 +01:00
?></a></h3>
<div class="card__content _small cell-desc">
<div class="text-overflow-ellipsis _bottom-spacer-xs">
<?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(
_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 ),
fictioneer_truncate( fictioneer_get_safe_title( $story_id ), 24 )
2023-01-21 01:31:34 +01:00
);
}
?>
</div>
<div class="text-overflow-ellipsis">
<?php
printf(
_x( '%1$s Words on %2$s', 'Small card: {n} Words on {Date}.', 'fictioneer' ),
2023-11-30 17:10:19 +01:00
fictioneer_shorten_number( fictioneer_get_word_count( $post->ID ) ),
get_the_time( FICTIONEER_LATEST_CHAPTERS_FOOTER_DATE )
2023-01-21 01:31:34 +01:00
);
?>
</div>
</div>
</div>
<div class="card__overlay-infobox _excerpt escape-last-click">
2024-01-19 22:24:08 +01:00
<div class="card__excerpt"><?php echo fictioneer_get_forced_excerpt( $post ); ?></div>
2023-01-21 01:31:34 +01:00
</div>
</div>
</li>
<?php endwhile; ?>
</ul>
2023-11-30 17:52:19 +01:00
<?php else : ?>
2023-01-21 01:31:34 +01:00
<div class="no-results"><?php _e( 'Nothing to show.', 'fictioneer' ); ?></div>
2023-01-21 01:31:34 +01:00
<?php endif; wp_reset_postdata(); ?>
</section>