fictioneer/partials/_card-recommendation.php

131 lines
4.5 KiB
PHP
Raw Normal View History

2023-01-21 01:31:34 +01:00
<?php
/**
* Partial: Recommendation Card
*
* @package WordPress
* @subpackage Fictioneer
* @since 4.0.0
2023-01-21 01:31:34 +01:00
*
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
// No direct access!
defined( 'ABSPATH' ) OR exit;
2023-01-21 01:31:34 +01:00
// Setup
$title = fictioneer_get_safe_title( $post->ID, 'card-recommendation' );
2023-10-02 00:02:12 +02:00
$links = array_merge(
2023-12-02 00:00:13 +01:00
fictioneer_url_list_to_array( get_post_meta( $post->ID, 'fictioneer_recommendation_urls', true ) ),
fictioneer_url_list_to_array( get_post_meta( $post->ID, 'fictioneer_recommendation_support', true ) )
2023-01-21 01:31:34 +01:00
);
2023-08-08 09:37:57 +02:00
$excerpt = get_the_excerpt();
2023-12-02 00:00:13 +01:00
$one_sentence = get_post_meta( $post->ID, 'fictioneer_recommendation_one_sentence', true );
$card_classes = [];
2023-01-21 01:31:34 +01:00
// Taxonomies
2023-08-08 09:37:57 +02:00
$tags = false;
$fandoms = false;
$characters = false;
$genres = false;
if (
get_option( 'fictioneer_show_tags_on_recommendation_cards' ) &&
! get_option( 'fictioneer_hide_taxonomies_on_recommendation_cards' )
) {
$tags = get_the_tags();
}
if ( ! get_option( 'fictioneer_hide_taxonomies_on_recommendation_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
$show_taxonomies = ! get_option( 'fictioneer_hide_taxonomies_on_recommendation_cards' ) && ( $tags || $genres || $fandoms || $characters );
2024-02-12 00:27:58 +01:00
// Extra classes
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-12 00:27:58 +01:00
}
2023-01-21 01:31:34 +01:00
?>
<li id="recommendation-card-<?php the_ID(); ?>" class="card _large _recommendation <?php echo implode( ' ', $card_classes ); ?>">
2023-01-21 01:31:34 +01:00
<div class="card__body polygon">
<div class="card__header _large">
<?php if ( $args['show_type'] ?? false ) : ?>
2023-01-21 01:31:34 +01:00
<div class="card__label"><?php _ex( 'Recommendation', 'Recommendation card label.', 'fictioneer' ); ?></div>
<?php endif; ?>
<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">
2023-08-08 09:37:57 +02:00
<?php
2024-01-27 22:32:10 +01:00
// Action hook
do_action( 'fictioneer_large_card_body_recommendation', $post, $args );
2023-08-08 09:37:57 +02:00
// Thumbnail
if ( has_post_thumbnail() ) {
2023-01-21 01:31:34 +01:00
printf(
2023-08-08 09:37:57 +02:00
'<a href="%1$s" title="%2$s" class="card__image cell-img" %3$s>%4$s</a>',
get_the_post_thumbnail_url( null, 'full' ),
sprintf( __( '%s Thumbnail', 'fictioneer' ), $title ),
fictioneer_get_lightbox_attribute(),
get_the_post_thumbnail( null, 'cover' )
2023-01-21 01:31:34 +01:00
);
2023-08-08 09:37:57 +02:00
}
// Content
printf(
2024-01-19 14:13:17 +01:00
'<div class="card__content cell-desc"><div class="truncate _4-4"><span class="card__by-author">%1$s</span> <span>%2$s</span></div></div>',
2023-08-08 09:37:57 +02:00
sprintf(
_x( 'by %s —', 'Large card: by {Author} —.', 'fictioneer' ),
2023-12-02 00:00:13 +01:00
get_post_meta( $post->ID, 'fictioneer_recommendation_author', true )
2023-08-08 09:37:57 +02:00
),
strlen( $one_sentence ) < strlen( $excerpt ) ? $excerpt : wp_strip_all_tags( $one_sentence, true )
);
?>
2023-01-21 01:31:34 +01:00
2023-10-02 00:02:12 +02:00
<?php if ( count( $links ) > 0 ): ?>
2023-01-21 01:31:34 +01:00
<ol class="card__link-list cell-list">
2023-10-02 00:02:12 +02:00
<?php foreach ( $links as $link ) : ?>
<li class="card__link-list-item">
2023-01-21 01:31:34 +01:00
<div class="card__left text-overflow-ellipsis">
<i class="fa-solid fa-square-up-right"></i>
2023-10-02 00:02:12 +02:00
<a href="<?php echo esc_url( $link['url'] ); ?>" rel="noopener" target="_blank" class="card__link-list-link"><?php echo $link['name']; ?></a>
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-08-08 09:37:57 +02:00
$taxonomies = array_merge(
$fandoms ? fictioneer_generate_card_tags( $fandoms, '_fandom' ) : [],
$genres ? fictioneer_generate_card_tags( $genres, '_genre' ) : [],
$tags ? fictioneer_generate_card_tags( $tags ) : [],
$characters ? fictioneer_generate_card_tags( $characters, '_character' ) : []
);
2023-06-04 01:49:00 +02:00
// Implode with three-per-em spaces around a bullet
2023-08-08 09:37:57 +02:00
echo implode( '&#8196;&bull;&#8196;', $taxonomies );
2023-01-21 01:31:34 +01:00
?>
</div>
<?php endif; ?>
</div>
</div>
</li>