2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Partial: Post Collection
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Fictioneer
|
|
|
|
* @since 4.0
|
|
|
|
*
|
2023-06-07 23:23:19 +02:00
|
|
|
* @internal $args['show_type'] Whether to show the post type label. Unsafe.
|
|
|
|
* @internal $args['cache'] Whether to account for active caching. Unsafe.
|
|
|
|
* @internal $args['order'] Current order. Default 'desc'. Unsafe.
|
|
|
|
* @internal $args['orderby'] Current orderby. Default 'modified'. Unsafe.
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
?>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
$list_title = trim( fictioneer_get_field( 'fictioneer_collection_list_title' ) );
|
|
|
|
$title = empty( $list_title ) ? fictioneer_get_safe_title( get_the_ID() ) : $list_title;
|
|
|
|
$description = fictioneer_get_content_field( 'fictioneer_collection_description' );
|
|
|
|
$items = fictioneer_get_field( 'fictioneer_collection_items' );
|
|
|
|
$items = empty( $items ) ? [] : $items;
|
|
|
|
$story_count = 0;
|
|
|
|
$chapter_count = 0;
|
|
|
|
$word_count = 0;
|
|
|
|
$processed_ids = [];
|
|
|
|
|
|
|
|
// Taxonomies
|
2023-08-08 00:15:26 +02:00
|
|
|
$tags = false;
|
|
|
|
$fandoms = false;
|
|
|
|
$characters = false;
|
|
|
|
$genres = false;
|
|
|
|
|
|
|
|
if (
|
|
|
|
get_option( 'fictioneer_show_tags_on_collection_cards' ) &&
|
|
|
|
! get_option( 'fictioneer_hide_taxonomies_on_collection_cards' )
|
|
|
|
) {
|
|
|
|
$tags = get_the_tags();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! get_option( 'fictioneer_hide_taxonomies_on_collection_cards' ) ) {
|
|
|
|
$fandoms = get_the_terms( $post->ID, 'fcn_fandom' );
|
|
|
|
$characters = get_the_terms( $post->ID, 'fcn_character' );
|
|
|
|
$genres = get_the_terms( $post->ID, 'fcn_genre' );
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Flags
|
2023-08-07 19:55:24 +02:00
|
|
|
$show_type = $args['show_type'] ?? false;
|
|
|
|
$show_taxonomies = ! get_option( 'fictioneer_hide_taxonomies_on_collection_cards' ) && ( $fandoms || $characters || $genres || $tags );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2023-08-08 00:15:26 +02:00
|
|
|
// Query featured posts
|
|
|
|
if ( ! empty( $items ) ) {
|
|
|
|
$items = new WP_Query(
|
|
|
|
array(
|
|
|
|
'post_type' => 'any',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'post__in' => $items,
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'orderby' => 'modified',
|
|
|
|
'posts_per_page' => -1,
|
|
|
|
'update_post_meta_cache' => false, // Improve performance
|
|
|
|
'update_post_term_cache' => false, // Improve performance
|
|
|
|
'no_found_rows' => true // Improve performance
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$items = $items->posts;
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Statistics
|
|
|
|
if ( ! empty( $items ) ) {
|
2023-08-08 00:15:26 +02:00
|
|
|
foreach ( $items as $item ) {
|
2023-01-21 01:31:34 +01:00
|
|
|
// Count by type
|
2023-08-08 00:15:26 +02:00
|
|
|
switch ( $item->post_type ) {
|
2023-01-21 01:31:34 +01:00
|
|
|
case 'fcn_chapter':
|
2023-08-08 00:15:26 +02:00
|
|
|
if ( ! in_array( $item->ID, $processed_ids ) ) {
|
2023-01-21 01:31:34 +01:00
|
|
|
$chapter_count += 1;
|
2023-08-08 00:15:26 +02:00
|
|
|
$word_count += get_post_meta( $item->ID, '_word_count', true );
|
|
|
|
$processed_ids[] = $item->ID;
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'fcn_story':
|
|
|
|
$story_count += 1;
|
2023-08-08 00:15:26 +02:00
|
|
|
$chapter_ids = fictioneer_get_field( 'fictioneer_story_chapters', $item->ID );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Try to rescue an empty description by using one from a story...
|
|
|
|
if ( empty( $description ) ) {
|
|
|
|
$description = fictioneer_first_paragraph_as_excerpt(
|
2023-08-08 00:15:26 +02:00
|
|
|
fictioneer_get_content_field( 'fictioneer_story_short_description', $item->ID )
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-08-08 00:15:26 +02:00
|
|
|
// Query eligible chapters
|
|
|
|
$chapter_query_args = array(
|
|
|
|
'post_type' => 'fcn_chapter',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'post__in' => $chapter_ids,
|
|
|
|
'posts_per_page' => -1,
|
|
|
|
'update_post_term_cache' => false, // Improve performance
|
|
|
|
'no_found_rows' => true // Improve performance
|
|
|
|
);
|
|
|
|
|
|
|
|
$chapters = new WP_Query( $chapter_query_args );
|
|
|
|
$chapters = $chapters->posts;
|
|
|
|
|
|
|
|
if ( ! empty( $chapters ) ) {
|
|
|
|
foreach ( $chapters as $chapter ) {
|
|
|
|
if ( fictioneer_get_field( 'fictioneer_chapter_no_chapter', $chapter->ID ) ) continue;
|
|
|
|
if ( fictioneer_get_field( 'fictioneer_chapter_hidden', $chapter->ID ) ) continue;
|
|
|
|
|
|
|
|
if ( ! in_array( $chapter->ID, $processed_ids ) ) {
|
|
|
|
$chapter_count += 1;
|
|
|
|
$word_count += get_post_meta( $chapter->ID, '_word_count', true );
|
|
|
|
$processed_ids[] = $chapter->ID;
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare features items
|
2023-08-08 00:15:26 +02:00
|
|
|
$items = array_slice( $items, 0, 3 );
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Required since it's possible to add chapters to collection outside of
|
|
|
|
// their stories, which would cause the comments to be counted twice.
|
2023-08-07 12:43:02 +02:00
|
|
|
$comment_args = array(
|
|
|
|
'post_type' => 'fcn_chapter',
|
2023-08-08 00:18:53 +02:00
|
|
|
'status' => 1,
|
2023-08-07 12:43:02 +02:00
|
|
|
'post__in' => $processed_ids,
|
|
|
|
'count' => true,
|
|
|
|
'update_comment_meta_cache' => false
|
|
|
|
);
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
$comment_count = get_comments( $comment_args );
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<li id="collection-card-<?php the_ID(); ?>" class="card">
|
|
|
|
<div class="card__body polygon">
|
|
|
|
|
|
|
|
<div class="card__header _large">
|
|
|
|
<?php if ( $show_type ) : ?>
|
|
|
|
<div class="card__label"><?php _ex( 'Collection', 'Collection card label.', 'fictioneer' ); ?></div>
|
|
|
|
<?php endif; ?>
|
2023-02-09 10:44:04 +01:00
|
|
|
<h3 class="card__title"><a href="<?php the_permalink(); ?>" class="truncate _1-1"><?php echo $title; ?></a></h3>
|
2023-01-21 01:31:34 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="card__main _grid _large">
|
|
|
|
|
|
|
|
<?php if ( has_post_thumbnail() ) : ?>
|
|
|
|
<a href="<?php the_post_thumbnail_url( 'full' ); ?>" title="<?php printf( __( '%s Thumbnail', 'fictioneer' ), $title ) ?>" class="card__image cell-img" <?php echo fictioneer_get_lightbox_attribute(); ?>><?php the_post_thumbnail( 'cover' ); ?></a>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
2023-02-09 10:44:04 +01:00
|
|
|
<div class="card__content cell-desc truncate <?php echo count( $items ) > 2 ? '_3-4' : '_4-4'; ?>"><span><?php echo $description; ?></span></div>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<?php if ( ! empty( $items ) ): ?>
|
|
|
|
<ol class="card__link-list cell-list">
|
|
|
|
<?php foreach ( $items as $post_id ) : ?>
|
|
|
|
<li>
|
|
|
|
<div class="card__left text-overflow-ellipsis">
|
|
|
|
<i class="fa-solid fa-caret-right"></i>
|
|
|
|
<a href="<?php the_permalink( $post_id ); ?>"><?php
|
|
|
|
$list_title = fictioneer_get_field( 'fictioneer_chapter_list_title', $post_id );
|
|
|
|
|
|
|
|
if ( $list_title ) {
|
|
|
|
echo wp_strip_all_tags( $list_title );
|
|
|
|
} else {
|
|
|
|
echo fictioneer_get_safe_title( $post_id );
|
|
|
|
}
|
|
|
|
?></a>
|
|
|
|
</div>
|
2023-06-06 13:44:16 +02:00
|
|
|
<div class="card__right">
|
|
|
|
<?php
|
|
|
|
echo get_post_type_object( get_post_type( $post_id ) )->labels->singular_name;
|
|
|
|
echo '<span class="separator-dot hide-below-480"> • </span><span class="hide-below-480">';
|
2023-06-06 22:01:29 +02:00
|
|
|
echo get_the_modified_date( FICTIONEER_CARD_COLLECTION_LI_DATE, $post_id );
|
2023-06-06 13:44:16 +02:00
|
|
|
echo '</span>';
|
|
|
|
?>
|
2023-01-21 01:31:34 +01:00
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
</ol>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
<?php if ( $show_taxonomies ) : ?>
|
2023-06-04 01:49:00 +02:00
|
|
|
<div class="card__tag-list cell-tax">
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
2023-06-04 01:49:00 +02:00
|
|
|
$output = [];
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
if ( $fandoms ) {
|
|
|
|
foreach ( $fandoms as $fandom ) {
|
2023-06-05 10:41:19 +02:00
|
|
|
$output[] = "<a href='" . get_tag_link( $fandom ) . "' class='tag-pill _inline _fandom'>{$fandom->name}</a>";
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $genres ) {
|
|
|
|
foreach ( $genres as $genre ) {
|
2023-06-05 10:41:19 +02:00
|
|
|
$output[] = "<a href='" . get_tag_link( $genre ) . "' class='tag-pill _inline _genre'>{$genre->name}</a>";
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $tags ) {
|
|
|
|
foreach ( $tags as $tag ) {
|
2023-06-05 10:41:19 +02:00
|
|
|
$output[] = "<a href='" . get_tag_link( $tag ) . "' class='tag-pill _inline'>{$tag->name}</a>";
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $characters ) {
|
|
|
|
foreach ( $characters as $character ) {
|
2023-06-05 10:41:19 +02:00
|
|
|
$output[] = "<a href='" . get_tag_link( $character ) . "' class='tag-pill _inline _character'>{$character->name}</a>";
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
}
|
2023-06-04 01:49:00 +02:00
|
|
|
|
|
|
|
// Implode with three-per-em spaces around a bullet
|
2023-06-04 02:05:11 +02:00
|
|
|
echo implode( ' • ', $output );
|
2023-01-21 01:31:34 +01:00
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="card__footer">
|
|
|
|
<div class="card__left text-overflow-ellipsis">
|
|
|
|
|
|
|
|
<i class="fa-solid fa-book" title="<?php esc_attr_e( 'Stories', 'fictioneer' ) ?>"></i>
|
2023-06-04 22:17:42 +02:00
|
|
|
<?php echo $story_count; ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<i class="fa-solid fa-list" title="<?php esc_attr_e( 'Chapters', 'fictioneer' ) ?>"></i>
|
2023-06-04 22:17:42 +02:00
|
|
|
<?php echo $chapter_count; ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<i class="fa-solid fa-font"></i>
|
2023-06-04 22:17:42 +02:00
|
|
|
<?php echo fictioneer_shorten_number( $word_count ); ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2023-06-07 23:34:46 +02:00
|
|
|
<?php if ( ( $args['orderby'] ?? 0 ) === 'date' ) : ?>
|
|
|
|
<i class="fa-solid fa-clock" title="<?php esc_attr_e( 'Published', 'fictioneer' ) ?>"></i>
|
2023-06-11 05:17:09 +02:00
|
|
|
<?php echo get_the_date( FICTIONEER_CARD_CHAPTER_FOOTER_DATE ); ?>
|
2023-06-07 23:34:46 +02:00
|
|
|
<?php else : ?>
|
|
|
|
<i class="fa-regular fa-clock" title="<?php esc_attr_e( 'Last Updated', 'fictioneer' ) ?>"></i>
|
|
|
|
<?php the_modified_date( FICTIONEER_CARD_COLLECTION_FOOTER_DATE ); ?>
|
|
|
|
<?php endif; ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<i class="fa-solid fa-message" title="<?php esc_attr_e( 'Comments', 'fictioneer' ) ?>"></i>
|
2023-08-08 00:18:53 +02:00
|
|
|
<?php echo number_format_i18n( $comment_count ); ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</li>
|