fictioneer/partials/_card-post.php

129 lines
4.3 KiB
PHP
Raw Normal View History

2023-01-21 01:31:34 +01:00
<?php
/**
* Partial: Post 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.
2023-01-21 01:31:34 +01:00
*/
// No direct access!
defined( 'ABSPATH' ) OR exit;
2023-01-21 01:31:34 +01:00
// Setup
2024-05-17 17:46:54 +02:00
$post_id = $post->ID;
$title = fictioneer_get_safe_title( $post_id, 'card-post' );
2023-01-21 01:31:34 +01:00
$tags = get_the_tags();
$categories = get_the_terms( $post_id, 'category' );
$card_classes = [];
2023-01-21 01:31:34 +01:00
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
}
2024-05-14 18:40:52 +02:00
if ( get_theme_mod( 'card_image_style', 'default' ) !== 'default' ) {
$card_classes[] = '_' . get_theme_mod( 'card_image_style' );
}
// Card attributes
$attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'card-post' );
$card_attributes = '';
foreach ( $attributes as $key => $value ) {
$card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" ';
}
2024-03-16 14:49:51 +01:00
// Thumbnail attributes
$thumbnail_args = array(
'alt' => sprintf( __( '%s Thumbnail', 'fictioneer' ), $title ),
'class' => 'no-auto-lightbox'
);
2023-01-21 01:31:34 +01:00
?>
2024-05-17 17:46:54 +02:00
<li id="post-card-<?php echo $post_id; ?>" class="post-<?php echo $post_id; ?> card _large _post <?php echo implode( ' ', $card_classes ); ?>" <?php echo $card_attributes; ?>>
2023-01-21 01:31:34 +01:00
<div class="card__body polygon">
<div class="card__main _grid _large">
2024-05-14 10:05:05 +02:00
<div class="card__header _large">
<?php if ( $args['show_type'] ?? false ) : ?>
<div class="card__label"><?php _ex( 'Blog', 'Blog card label.', 'fictioneer' ); ?></div>
<?php endif; ?>
<h3 class="card__title"><a href="<?php the_permalink(); ?>" class="truncate _1-1"><?php echo $title; ?></a></h3>
</div>
2023-08-08 10:49:46 +02:00
<?php
2024-01-27 22:32:10 +01:00
// Action hook
do_action( 'fictioneer_large_card_body_post', $post, $args );
2023-08-08 10:49:46 +02:00
// Thumbnail
2024-05-14 18:40:52 +02:00
if ( has_post_thumbnail() && get_theme_mod( 'card_image_style', 'default' ) !== 'none' ) {
2023-08-08 10:49:46 +02:00
printf(
'<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(),
2024-03-16 14:49:51 +01:00
get_the_post_thumbnail( null, 'cover', $thumbnail_args )
2023-08-08 10:49:46 +02:00
);
}
?>
2023-01-21 01:31:34 +01:00
2024-01-19 14:13:17 +01:00
<div class="card__content cell-desc"><div class="truncate _4-4"><span><?php the_excerpt(); ?></span></div></div>
2023-01-21 01:31:34 +01:00
2024-08-23 23:35:49 +02:00
<?php
$terms = [];
if ( $categories || $tags ) {
$terms = array_merge(
$categories ? fictioneer_get_term_nodes( $categories, '_inline _category' ) : [],
$tags ? fictioneer_get_term_nodes( $tags, '_inline _tag' ) : []
);
$terms = apply_filters(
'fictioneer_filter_card_post_terms',
$terms, $post, $args, null
);
}
?>
<?php if ( $terms ) : ?>
<div class="card__tag-list cell-tax"><?php
// Implode with separator
echo implode( fictioneer_get_bullet_separator( 'post-card' ), $terms );
?></div>
2023-01-21 01:31:34 +01:00
<?php endif; ?>
2024-05-13 23:26:51 +02:00
<div class="card__footer cell-footer">
2023-01-21 01:31:34 +01:00
2024-05-13 23:26:51 +02:00
<div class="card__footer-box text-overflow-ellipsis"><?php
// Build footer items
$footer_items = [];
2023-08-08 10:49:46 +02:00
2024-05-13 23:26:51 +02:00
if ( get_option( 'fictioneer_show_authors' ) ) {
$footer_items['author'] = '<span class="card__footer-author"><i class="card-footer-icon fa-solid fa-circle-user"></i> ' . fictioneer_get_author_node( get_the_author_meta( 'ID' ) ) . '</span>';
2024-05-13 23:26:51 +02:00
}
2023-08-08 10:49:46 +02:00
$footer_items['publish_date'] = '<span class="card__footer-publish-date"><i class="card-footer-icon fa-solid fa-clock" title="' . esc_attr__( 'Published', 'fictioneer' ) .'"></i> ' . get_the_date( FICTIONEER_CARD_POST_FOOTER_DATE ) . '</span>';
2023-08-30 02:32:39 +02:00
$footer_items['comments'] = '<span class="card__footer-comments"><i class="card-footer-icon fa-solid fa-message" title="' . esc_attr__( 'Comments', 'fictioneer' ) . '"></i> ' . get_comments_number( $post ) . '</span>';
2023-08-08 10:49:46 +02:00
2024-05-13 23:26:51 +02:00
// Filter footer items
$footer_items = apply_filters( 'fictioneer_filter_post_card_footer', $footer_items, $post, $args );
2023-08-08 10:49:46 +02:00
2024-05-13 23:26:51 +02:00
// Implode and render footer items
echo implode( ' ', $footer_items );
?></div>
2023-08-08 10:49:46 +02:00
2024-05-13 23:26:51 +02:00
</div>
2023-08-08 10:49:46 +02:00
2023-01-21 01:31:34 +01:00
</div>
</div>
</li>