2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Partial: Latest Recommendations
|
|
|
|
*
|
|
|
|
* Renders the (buffered) HTML for the [fictioneer_latest_recommendations] shortcode.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Fictioneer
|
|
|
|
* @since 4.0
|
|
|
|
*
|
2023-08-19 22:22:56 +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['post_ids'] Array of post IDs. 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['taxonomies'] Array of taxonomy arrays. Default empty.
|
|
|
|
* @internal $args['relation'] Relationship between taxonomies.
|
|
|
|
* @internal $args['class'] Additional classes.
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
?>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
2023-08-20 20:21:48 +02:00
|
|
|
// No direct access!
|
|
|
|
defined( 'ABSPATH' ) OR exit;
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// Setup
|
|
|
|
$show_taxonomies = ! get_option( 'fictioneer_hide_taxonomies_on_recommendation_cards' );
|
|
|
|
|
|
|
|
// Prepare query
|
|
|
|
$query_args = array (
|
|
|
|
'post_type' => 'fcn_recommendation',
|
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-01-21 01:31:34 +01:00
|
|
|
'orderby' => $args['orderby'] ?? 'date',
|
|
|
|
'order' => $args['order'] ?? 'desc',
|
|
|
|
'posts_per_page' => $args['count'],
|
|
|
|
'no_found_rows' => true
|
|
|
|
);
|
|
|
|
|
|
|
|
// Parameter for author?
|
|
|
|
if ( isset( $args['author'] ) && $args['author'] ) $query_args['author_name'] = $args['author'];
|
|
|
|
|
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:16:54 +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-03-09 11:21:05 +01:00
|
|
|
// Apply filters
|
2023-03-10 15:20:48 +01:00
|
|
|
$query_args = apply_filters( 'fictioneer_filter_shortcode_latest_recommendations_query_args', $query_args, $args );
|
2023-03-09 11:21:05 +01:00
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// Query recommendations
|
2023-08-03 13:17:32 +02:00
|
|
|
$entries = fictioneer_shortcode_query( $query_args );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
?>
|
|
|
|
|
2023-01-27 01:23:02 +01:00
|
|
|
<section class="small-card-block latest-recommendations <?php echo implode( ' ', $args['classes'] ); ?>">
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<?php if ( $entries->have_posts() ) : ?>
|
|
|
|
|
|
|
|
<ul class="two-columns _collapse-on-mobile">
|
|
|
|
<?php while ( $entries->have_posts() ) : $entries->the_post(); ?>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
// Setup
|
|
|
|
$title = fictioneer_get_safe_title( get_the_ID() );
|
|
|
|
$one_sentence = fictioneer_get_field( 'fictioneer_recommendation_one_sentence' );
|
|
|
|
$fandoms = get_the_terms( $post, 'fcn_fandom' );
|
|
|
|
$characters = get_the_terms( $post, 'fcn_character' );
|
|
|
|
$genres = get_the_terms( $post, 'fcn_genre' );
|
|
|
|
$tags = get_option( 'fictioneer_show_tags_on_recommendation_cards' ) ? get_the_tags( $post ) : false;
|
|
|
|
|
|
|
|
// Sources
|
|
|
|
$urls = array_merge(
|
|
|
|
explode( "\n", fictioneer_get_field( 'fictioneer_recommendation_urls' ) ),
|
|
|
|
explode( "\n", fictioneer_get_field( 'fictioneer_recommendation_support' ) )
|
|
|
|
);
|
|
|
|
|
|
|
|
// Sanitize
|
|
|
|
$urls = array_map( 'wp_strip_all_tags', $urls );
|
|
|
|
|
|
|
|
// Remove empty nodes
|
|
|
|
$urls = array_filter( $urls );
|
|
|
|
|
|
|
|
// Abort if no links found
|
2023-08-28 10:43:04 +02:00
|
|
|
if ( empty( $urls ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Extract first link
|
|
|
|
$url = $urls[0];
|
|
|
|
$tuple = explode( '|', $url );
|
|
|
|
$tuple = array_map( 'trim', $tuple );
|
|
|
|
?>
|
|
|
|
|
|
|
|
<li class="card _small">
|
|
|
|
<div class="card__body polygon">
|
|
|
|
|
|
|
|
<div class="card__main _grid _small">
|
|
|
|
|
|
|
|
<?php if ( has_post_thumbnail() ) : ?>
|
|
|
|
<a href="<?php the_post_thumbnail_url( 'full' ); ?>" title="<?php echo esc_attr( sprintf( __( '%s Thumbnail', 'fictioneer' ), $title ) ); ?>" class="card__image cell-img" <?php echo fictioneer_get_lightbox_attribute(); ?>>
|
|
|
|
<?php echo get_the_post_thumbnail( $post, 'snippet', ['class' => 'no-auto-lightbox'] ); ?>
|
|
|
|
</a>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
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 echo $title; ?></a></h3>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<div class="card__content _small cell-meta text-overflow-ellipsis">
|
2023-06-04 14:02:12 +02:00
|
|
|
<span class="card__by-author"><?php
|
2023-01-21 01:31:34 +01:00
|
|
|
printf(
|
2023-06-04 14:02:12 +02:00
|
|
|
_x( 'by %s on', 'Small card: by {Author} on.', 'fictioneer' ),
|
|
|
|
'<span class="author">' . fictioneer_get_field( 'fictioneer_recommendation_author' ) . '</span>'
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
2023-06-04 14:02:12 +02:00
|
|
|
?></span>
|
|
|
|
<a href="<?php echo esc_url( $tuple[1] ); ?>" rel="noopener" target="_blank" class="bold-link"><?php
|
|
|
|
echo $tuple[0];
|
|
|
|
?></a>
|
2023-01-21 01:31:34 +01:00
|
|
|
</div>
|
|
|
|
|
2023-02-09 10:44:04 +01:00
|
|
|
<div class="card__content _small cell-desc truncate _3-3">
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
|
|
|
if ( ! empty( $one_sentence ) ) {
|
|
|
|
echo wp_strip_all_tags( $one_sentence, true );
|
|
|
|
} else {
|
|
|
|
echo fictioneer_first_paragraph_as_excerpt( get_the_content() );
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php if ( $show_taxonomies ) : ?>
|
|
|
|
<div class="card__tag-list _small _scrolling cell-tax">
|
2023-08-30 10:42:10 +02:00
|
|
|
<div class="card__h-scroll">
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
|
|
|
if ( $fandoms || $characters || $genres || $tags ) {
|
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-04 01:49:00 +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-04 01:49:00 +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-04 01:49:00 +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-04 01:49:00 +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
|
|
|
} else {
|
|
|
|
?><span class="card__no-taxonomies"><?php _e( 'No taxonomies specified yet.', 'fictioneer' ); ?></span><?php
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<?php endwhile; ?>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
|
|
|
<div class="no-results"><?php _e( 'No recommendations have been published yet.', 'fictioneer' ) ?></div>
|
|
|
|
|
|
|
|
<?php endif; wp_reset_postdata(); ?>
|
|
|
|
|
|
|
|
</section>
|