commit e76d41be04166ad5a9a1a17d327a9b47d46149f7 Merge: 9490b992 48b6cf37 Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Fri Sep 6 01:26:29 2024 +0200 Merge branch 'main' into splide commit 9490b9925ff2ff78f3057a2762aa41aa61028a68 Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Fri Sep 6 00:02:52 2024 +0200 Add height and aspect_ratio params to showcase commit 8043e35abb95d04192ba5a9399480a37db647b27 Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu Sep 5 23:02:12 2024 +0200 Add Splide to showcase shortcode commit bc7344d3a89eea93a0727b88c7d7998a2f73b54b Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu Sep 5 22:52:26 2024 +0200 Start documentation commit 3e3183e5ec3da66c585f022af1214b3690ad84f6 Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu Sep 5 22:13:41 2024 +0200 Add option to enable Splide globally commit 60935c24e647889beab8b158bb50aa1f4948e4da Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu Sep 5 20:48:44 2024 +0200 Elementor compatibility commit 1f7c0ca40289597af0b6a250c62ed22621a9668a Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu Sep 5 20:39:08 2024 +0200 Optimize Splide for paginated article cards commit 911c0f6f20d0c3a5bddda280618064eb1309ac5f Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu Sep 5 20:24:52 2024 +0200 Turn off arrows by default commit 567205b42031b9e075060c208d1fb93507c7acfa Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu Sep 5 14:05:46 2024 +0200 Move SCSS to own file commit 5a91f1dcf0982a78e22362262d4b982784cfdd21 Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu Sep 5 13:57:22 2024 +0200 Update style commit e3c920ab33c5d6065fd7b8a7f2211d8809630df3 Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu Sep 5 11:58:52 2024 +0200 Add Splide to other shortcodes commit 7c2275a0c336e7ca7072165d633dd3fbc8a19524 Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu Sep 5 11:55:39 2024 +0200 Update style commit 68bff5aef85af82f1a844de293f443172a5e5d1e Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Wed Sep 4 19:16:55 2024 +0200 Improve error handling of invalid JSON commit ce9159425a6d6674cdef7d8f356724c79db3130b Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Wed Sep 4 19:05:01 2024 +0200 Improve Splide loading and initialization commit 263848a53ddfb77980f88b5b5f973311d792e712 Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Wed Sep 4 16:39:18 2024 +0200 Improve JSON preparation commit 8c39131008a50119bd8666b558f01354140c0b00 Merge: d4373db4 57638cdc Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Wed Sep 4 14:19:28 2024 +0200 Merge branch 'main' into splide commit d4373db473e80b05c52565f25ba13034eb81d648 Author: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Wed Sep 4 13:48:00 2024 +0200 Prototype
213 lines
7.5 KiB
PHP
213 lines
7.5 KiB
PHP
<?php
|
|
/**
|
|
* Partial: Showcase
|
|
*
|
|
* This template part renders a showcase of posts and can be called with the
|
|
* [fictioneer_showcase for="post_type" count order orderby author post_ids]
|
|
* shortcode. Posts are displayed as grid with a maximum of three columns,
|
|
* collapsing to one on mobile.
|
|
*
|
|
* @package WordPress
|
|
* @subpackage Fictioneer
|
|
* @since 4.0.0
|
|
*
|
|
* @internal $args['post_type'] Post type if the showcase.
|
|
* @internal $args['count'] Maximum number of items. Default 8.
|
|
* @internal $args['order'] Order direction. Default 'DESC'.
|
|
* @internal $args['orderby'] Order argument. Default 'date'.
|
|
* @internal $args['author'] Author provided by the shortcode.
|
|
* @internal $args['post_ids'] Array of post IDs. Default empty.
|
|
* @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.
|
|
* @internal $args['classes'] String of additional CSS classes. Default empty.
|
|
* @internal $args['splide'] Configuration JSON for the Splide slider. Default empty.
|
|
* @internal $args['height'] Override the item height. Default empty.
|
|
* @internal $args['aspect_ratio'] Aspect ratio of the item. Superseded by height. Default empty.
|
|
*/
|
|
|
|
|
|
// No direct access!
|
|
defined( 'ABSPATH' ) OR exit;
|
|
|
|
// Setup
|
|
$splide = $args['splide'] ?? 0;
|
|
|
|
// Prepare query
|
|
$query_args = array (
|
|
'fictioneer_query_name' => 'showcase',
|
|
'post_type' => $args['post_type'],
|
|
'post_status' => 'publish',
|
|
'post__in' => $args['post_ids'], // May be empty!
|
|
'order' => $args['order'],
|
|
'orderby' => $args['orderby'],
|
|
'posts_per_page' => $args['count'],
|
|
'update_post_term_cache' => false,
|
|
'no_found_rows' => true
|
|
);
|
|
|
|
// Author?
|
|
if ( ! empty( $args['author'] ) ) {
|
|
$query_args['author_name'] = $args['author'];
|
|
}
|
|
|
|
// Author IDs?
|
|
if ( ! empty( $args['author_ids'] ) ) {
|
|
$query_args['author__in'] = $args['author_ids'];
|
|
}
|
|
|
|
// 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
|
|
$query_args = apply_filters( 'fictioneer_filter_shortcode_showcase_query_args', $query_args, $args );
|
|
|
|
// Query collections
|
|
$query = fictioneer_shortcode_query( $query_args );
|
|
|
|
// Remove temporary filters
|
|
remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
|
|
|
|
// Extra attributes
|
|
$attributes = [];
|
|
|
|
if ( $splide ) {
|
|
$attributes[] = "data-splide='{$splide}'";
|
|
}
|
|
|
|
?>
|
|
|
|
<?php if ( $query->have_posts() ) : ?>
|
|
<section class="showcase container-inline-size <?php echo $args['classes']; ?>" <?php echo implode( ' ', $attributes ); ?>>
|
|
<?php
|
|
if ( $args['splide'] === false ) {
|
|
echo '<div class="shortcode-json-invalid">' . __( 'Splide JSON is invalid and has been ignored.', 'fictioneer' ) . '</div>';
|
|
}
|
|
|
|
if ( $splide ) {
|
|
echo '<div class="splide__track">';
|
|
}
|
|
|
|
// Item classes
|
|
$item_classes = '';
|
|
|
|
if ( $args['aspect_ratio'] ) {
|
|
$item_classes .= ' _aspect-ratio';
|
|
}
|
|
|
|
if ( $args['height'] ) {
|
|
$item_classes .= ' _custom-height';
|
|
}
|
|
|
|
if ( $splide ) {
|
|
$item_classes .= ' splide__slide';
|
|
}
|
|
|
|
// Item attributes
|
|
$attributes = array(
|
|
'style' => ''
|
|
);
|
|
|
|
if ( $args['aspect_ratio'] ) {
|
|
$attributes['style'] .= "--showcase-item-aspect-ratio: {$args['aspect_ratio']};";
|
|
}
|
|
|
|
if ( $args['height'] ) {
|
|
$attributes['style'] .= "--showcase-item-height: {$args['height']};";
|
|
}
|
|
|
|
$item_attributes = '';
|
|
|
|
foreach ( $attributes as $key => $value ) {
|
|
$item_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" ';
|
|
}
|
|
?>
|
|
|
|
<ul class="showcase__list <?php if ( $splide ) { echo 'splide__list'; } ?>">
|
|
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
|
|
<li class="showcase__list-item <?php echo $item_classes; ?>" <?php echo $item_attributes; ?>>
|
|
<a class="showcase__list-item-link polygon" href="<?php the_permalink(); ?>">
|
|
<figure class="showcase__list-item-figure">
|
|
<?php
|
|
// Setup
|
|
$post_id = $post->ID;
|
|
$list_title = '';
|
|
$story_id = null;
|
|
$landscape_image_id = get_post_meta( $post_id, 'fictioneer_landscape_image', true );
|
|
|
|
// Get list title and story ID (if any)
|
|
switch ( $args['post_type'] ) {
|
|
case 'fcn_collection':
|
|
$list_title = get_post_meta( $post_id, 'fictioneer_collection_list_title', true );
|
|
break;
|
|
case 'fcn_chapter':
|
|
$list_title = get_post_meta( $post_id, 'fictioneer_chapter_list_title', true );
|
|
$story_id = get_post_meta( $post_id, 'fictioneer_chapter_story', true );
|
|
|
|
if ( empty( $landscape_image_id ) ) {
|
|
$landscape_image_id = get_post_meta( $story_id, 'fictioneer_landscape_image', true );
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
// Prepare titles
|
|
$list_title = trim( wp_strip_all_tags( $list_title ) );
|
|
$title = empty( $list_title ) ? fictioneer_get_safe_title( $post_id, 'shortcode-showcase' ) : $list_title;
|
|
|
|
// Prepare image arguments
|
|
$image_args = array(
|
|
'alt' => sprintf( __( '%s Cover', 'fictioneer' ), $title ),
|
|
'class' => 'no-auto-lightbox showcase__image'
|
|
);
|
|
|
|
// Output image or placeholder
|
|
if ( ! empty( $landscape_image_id ) ) {
|
|
echo wp_get_attachment_image( $landscape_image_id, 'medium', false, $image_args );
|
|
} elseif ( has_post_thumbnail() ) {
|
|
the_post_thumbnail( 'medium', $image_args );
|
|
} elseif ( $story_id && has_post_thumbnail( $story_id ) ) {
|
|
echo get_the_post_thumbnail( $story_id, 'medium', $image_args );
|
|
} else {
|
|
echo '<div class="showcase__image _no-cover"></div>';
|
|
}
|
|
?>
|
|
<?php if ( ! $args['no_cap'] ) : ?>
|
|
<figcaption class="showcase__list-item-figcaption"><?php echo $title; ?></figcaption>
|
|
<?php endif; ?>
|
|
</figure>
|
|
</a>
|
|
</li>
|
|
<?php endwhile; ?>
|
|
</ul>
|
|
|
|
<?php if ( $splide ) { echo '</div>'; } ?>
|
|
</section>
|
|
<?php endif; wp_reset_postdata(); ?>
|