57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
// Récupérer les paramètres
|
|
$post_id = $args['post_id'] ?? get_the_ID();
|
|
$post_type = $args['post_type'] ?? get_post_type($post_id);
|
|
$search = $args['search'] ?? get_search_query();
|
|
$isInnerSearch = $args['isInnerSearch'] ?? false;
|
|
|
|
|
|
// Récupérer les informations du post
|
|
$post_type_object = get_post_type_object($post_type);
|
|
$post_type_label = $post_type_object->labels->singular_name;
|
|
$title = get_the_title($post_id);
|
|
$permalink = get_the_permalink($post_id);
|
|
$date = get_the_date('F Y', $post_id);
|
|
|
|
// Mise en évidence des termes recherchés dans le titre
|
|
if (!empty($search)) {
|
|
$search_terms = explode(' ', $search);
|
|
foreach ($search_terms as $term) {
|
|
if (strlen(trim($term)) > 2) {
|
|
$term_escaped = preg_quote(trim($term), '/');
|
|
$title = preg_replace(
|
|
'/(' . $term_escaped . ')/i',
|
|
'<mark class="search-highlight">$1</mark>',
|
|
$title
|
|
);
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="search-results-card <?php echo $isInnerSearch ? 'search-results-card--inner-search' : ''; ?>">
|
|
<?php if (!$isInnerSearch) : ?>
|
|
<div class="content-meta">
|
|
<span class="content-meta__type content-meta__type--<?php echo $post_type; ?>"><?php echo $post_type_label; ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<h2 class="search-results-card__title">
|
|
<a href="<?php echo $permalink; ?>">
|
|
<?php echo $title; ?>
|
|
</a>
|
|
</h2>
|
|
<date class="search-results-card__parution-date">
|
|
<?php echo $date; ?>
|
|
</date>
|
|
<div class="search-results-page__search-snippet">
|
|
<?php echo get_search_snippet($post_id, $search); ?>
|
|
</div>
|
|
|
|
<?php get_template_part('template-parts/components/cta--go', null, array(
|
|
'url' => $permalink,
|
|
'label' => 'Lire la suite',
|
|
'target' => '_self',
|
|
)); ?>
|
|
|
|
</div>
|