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
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 4.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*
|
2024-01-28 00:11:56 +01:00
|
|
|
* @internal $args['type'] Type argument passed from shortcode ('compact').
|
2023-09-15 15:15:45 +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.
|
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.
|
2023-09-15 15:15:45 +02:00
|
|
|
* @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.
|
2024-04-14 18:18:03 +02:00
|
|
|
* @internal $args['vertical'] Whether to show the vertical variant.
|
2024-05-15 09:57:43 +02:00
|
|
|
* @internal $args['seamless'] Whether to render the image seamless. Default false (Customizer).
|
2024-04-14 18:18:03 +02:00
|
|
|
* @internal $args['aspect_ratio'] Aspect ratio for the image. Only with vertical.
|
2024-04-25 12:50:42 +02:00
|
|
|
* @internal $args['lightbox'] Whether the image is opened in the lightbox. Default true.
|
2024-05-15 09:57:43 +02:00
|
|
|
* @internal $args['thumbnail'] Whether the image is rendered. Default true (Customizer).
|
2023-09-15 22:42:34 +02:00
|
|
|
* @internal $args['classes'] String of additional CSS classes. Default empty.
|
2024-08-14 01:48:21 +02:00
|
|
|
* @internal $args['infobox'] Whether to show the info box and toggle.
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
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(
|
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',
|
2023-08-17 01:32:02 +02:00
|
|
|
'post__in' => $args['post_ids'], // May be empty!
|
2023-09-16 22:59:43 +02:00
|
|
|
'order' => $args['order'],
|
|
|
|
'orderby' => $args['orderby'],
|
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
|
|
|
'no_found_rows' => true,
|
2024-01-28 18:59:23 +01:00
|
|
|
'update_post_term_cache' => false
|
|
|
|
);
|
|
|
|
|
|
|
|
// Use extended meta query?
|
2024-01-28 19:55:54 +01:00
|
|
|
if ( get_option( 'fictioneer_disable_extended_chapter_list_meta_queries' ) ) {
|
2024-01-28 20:45:32 +01:00
|
|
|
$query_args['meta_key'] = 'fictioneer_chapter_hidden';
|
|
|
|
$query_args['meta_value'] = '0';
|
2024-01-28 18:59:23 +01:00
|
|
|
} else {
|
|
|
|
$query_args['meta_query'] = array(
|
2024-01-28 19:55:54 +01:00
|
|
|
'relation' => 'OR',
|
2024-01-28 18:59:23 +01:00
|
|
|
array(
|
|
|
|
'key' => 'fictioneer_chapter_hidden',
|
|
|
|
'value' => '0'
|
2024-01-28 19:55:54 +01:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'key' => 'fictioneer_chapter_hidden',
|
|
|
|
'compare' => 'NOT EXISTS'
|
2024-01-28 18:59:23 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2023-09-16 22:59:43 +02:00
|
|
|
// Author?
|
2023-09-17 01:28:14 +02:00
|
|
|
if ( ! empty( $args['author'] ) ) {
|
2023-09-16 22:59:43 +02:00
|
|
|
$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 );
|
|
|
|
}
|
|
|
|
|
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-09-16 22:59:43 +02:00
|
|
|
// Excluded authors?
|
|
|
|
if ( ! empty( $args['excluded_authors'] ) ) {
|
|
|
|
$query_args['author__not_in'] = $args['excluded_authors'];
|
|
|
|
}
|
|
|
|
|
2023-09-15 15:15:45 +02:00
|
|
|
// Ignore protected?
|
|
|
|
if ( $args['ignore_protected'] ) {
|
|
|
|
add_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
|
|
|
|
}
|
|
|
|
|
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-09-15 15:15:45 +02: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() ) : ?>
|
|
|
|
|
2024-01-19 14:55:50 +01:00
|
|
|
<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
|
2024-05-17 17:46:54 +02:00
|
|
|
$post_id = $post->ID;
|
|
|
|
$story_id = get_post_meta( $post_id, 'fictioneer_chapter_story', true );
|
2023-08-17 21:46:17 +02:00
|
|
|
|
|
|
|
if ( get_post_status( $story_id ) !== 'publish' ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-05-17 17:46:54 +02:00
|
|
|
$title = fictioneer_get_safe_title( $post_id, 'shortcode-latest-chapters-compact' );
|
2024-01-28 00:19:44 +01:00
|
|
|
$story = $story_id ? fictioneer_get_story_data( $story_id, false ) : null; // Does not refresh comment count!
|
2024-05-17 17:46:54 +02:00
|
|
|
$text_icon = get_post_meta( $post_id, 'fictioneer_chapter_text_icon', true );
|
2024-06-03 12:02:30 +02:00
|
|
|
$words = fictioneer_get_word_count( $post_id );
|
2024-04-14 18:18:03 +02:00
|
|
|
$grid_or_vertical = $args['vertical'] ? '_vertical' : '_grid';
|
2024-02-12 00:27:58 +01:00
|
|
|
$card_classes = [];
|
2024-02-06 03:10:02 +01:00
|
|
|
|
|
|
|
// Extra card classes
|
|
|
|
if ( ! empty( $post->post_password ) ) {
|
2024-02-12 00:27:58 +01:00
|
|
|
$card_classes[] = '_password';
|
|
|
|
}
|
|
|
|
|
2024-02-12 01:40:38 +01:00
|
|
|
if ( get_theme_mod( 'card_style', 'default' ) !== 'default' ) {
|
|
|
|
$card_classes[] = '_' . get_theme_mod( 'card_style' );
|
2024-02-06 03:10:02 +01:00
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-04-14 18:18:03 +02:00
|
|
|
if ( $args['vertical'] ) {
|
|
|
|
$card_classes[] = '_vertical';
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-14 18:40:52 +02:00
|
|
|
if ( $args['seamless'] ) {
|
2024-04-14 18:18:03 +02:00
|
|
|
$card_classes[] = '_seamless';
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
2023-08-17 21:46:17 +02:00
|
|
|
|
|
|
|
// Count actually rendered cards to account for buffer
|
2023-11-13 11:05:05 +01:00
|
|
|
if ( ++$card_counter > $args['count'] ) {
|
|
|
|
break;
|
|
|
|
}
|
2024-03-04 01:54:53 +01:00
|
|
|
|
|
|
|
// Card attributes
|
2024-04-14 18:18:03 +02:00
|
|
|
$attributes = [];
|
|
|
|
|
|
|
|
if ( $args['aspect_ratio'] ) {
|
|
|
|
$attributes['style'] = '--card-image-aspect-ratio: ' . $args['aspect_ratio'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$attributes = apply_filters( 'fictioneer_filter_card_attributes', $attributes, $post, 'shortcode-latest-chapters-compact' );
|
|
|
|
|
2024-03-04 01:54:53 +01:00
|
|
|
$card_attributes = '';
|
|
|
|
|
|
|
|
foreach ( $attributes as $key => $value ) {
|
|
|
|
$card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" ';
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
?>
|
|
|
|
|
2024-05-17 17:46:54 +02:00
|
|
|
<li class="post-<?php echo $post_id; ?> card watch-last-clicked _small _info _chapter _compact _no-footer <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
|
2023-01-21 01:31:34 +01:00
|
|
|
<div class="card__body polygon">
|
|
|
|
|
2024-08-14 01:48:21 +02:00
|
|
|
<?php if ( $words > 0 && $args['infobox'] ) : ?>
|
2024-06-03 12:02:30 +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>
|
|
|
|
<?php endif; ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-04-14 18:18:03 +02:00
|
|
|
<div class="card__main <?php echo $grid_or_vertical; ?> _small">
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-04-17 14:36:00 +02:00
|
|
|
<?php
|
|
|
|
do_action( 'fictioneer_shortcode_latest_chapters_card_body', $post, $story, $args );
|
|
|
|
|
2024-04-18 12:03:00 +02:00
|
|
|
if ( $args['thumbnail'] ) {
|
2024-08-18 14:21:37 +02:00
|
|
|
fictioneer_render_thumbnail(
|
2024-04-18 12:03:00 +02:00
|
|
|
array(
|
2024-05-17 17:46:54 +02:00
|
|
|
'post_id' => $post_id,
|
2024-04-18 12:03:00 +02:00
|
|
|
'title' => $title,
|
|
|
|
'classes' => 'card__image cell-img',
|
|
|
|
'permalink' => get_permalink(),
|
2024-04-18 16:09:27 +02:00
|
|
|
'lightbox' => $args['lightbox'],
|
2024-04-18 12:03:00 +02:00
|
|
|
'vertical' => $args['vertical'],
|
|
|
|
'seamless' => $args['seamless'],
|
|
|
|
'aspect_ratio' => $args['aspect_ratio'],
|
|
|
|
'text_icon' => $text_icon
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2024-04-17 14:36:00 +02:00
|
|
|
?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
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
|
2024-05-17 17:46:54 +02: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">
|
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'] ) {
|
2024-04-14 23:09:11 +02:00
|
|
|
$story_link = get_post_meta( $story_id, 'fictioneer_story_redirect_link', true )
|
|
|
|
?: get_permalink( $story_id );
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
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' ),
|
2024-04-14 23:09:11 +02:00
|
|
|
$story_link,
|
2024-03-01 12:39:42 +01:00
|
|
|
fictioneer_truncate( fictioneer_get_safe_title( $story_id, 'shortcode-latest-chapters-compact' ), 24 )
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</div>
|
2024-06-03 12:02:30 +02:00
|
|
|
<div class="card__words-on-date text-overflow-ellipsis">
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
2024-06-03 12:02:30 +02:00
|
|
|
if ( $words > 0 ) {
|
|
|
|
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 );
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2024-08-14 01:48:21 +02:00
|
|
|
<?php if ( $words > 0 && $args['infobox'] ) : ?>
|
2024-06-03 12:02:30 +02:00
|
|
|
<div class="card__overlay-infobox _excerpt escape-last-click">
|
|
|
|
<div class="card__excerpt"><?php
|
|
|
|
echo fictioneer_get_forced_excerpt( $post, $args['vertical'] ? 512 : 256 );
|
|
|
|
?></div>
|
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<?php endwhile; ?>
|
|
|
|
</ul>
|
|
|
|
|
2023-11-30 17:52:19 +01:00
|
|
|
<?php else : ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2023-09-15 22:55:59 +02: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>
|