-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.php
More file actions
105 lines (94 loc) · 3.91 KB
/
Copy pathcontent.php
File metadata and controls
105 lines (94 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Template part for displaying a single post card on index and archive pages.
*
* Renders one post card inside the Loop. Handles featured image display with
* format-aware wrapper elements, the sticky-post badge, entry header, entry
* meta (author, date, comments, categories), and a smart excerpt that
* respects manual <!--more--> breaks.
*
* @package Canard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
// Cached once — used in both the thumbnail conditional and the entry-meta conditional.
$post_type = get_post_type();
?>
<?php if ( has_post_thumbnail() && 'post' === $post_type && ( ! has_post_format() || has_post_format( 'image' ) || has_post_format( 'gallery' ) ) ) : ?>
<?php
if ( ! has_post_format() ) {
echo '<a class="post-thumbnail" href="' . esc_url( get_permalink() ) . '">';
} elseif ( has_post_format( 'image' ) || has_post_format( 'gallery' ) ) {
echo '<div class="post-thumbnail">';
}
// Loading strategy is intentionally left to WordPress core's
// wp_get_loading_optimization_attributes() (WP 6.3+): the first
// post card's thumbnail is the LCP candidate on home/archive views
// and should receive fetchpriority="high" without lazy-loading,
// while later cards are lazy-loaded automatically. Only the sizes
// attribute is overridden, since the post list container is
// narrower than the viewport when the sidebar is present.
the_post_thumbnail( 'canard-post-thumbnail', [
'sizes' => '(max-width: 767px) 100vw, (max-width: 1039px) 50vw, 620px',
] );
?>
<?php if ( is_sticky() ) : ?>
<span class="sticky-post"><svg aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16"><path d="M16 3a1 1 0 00-1 1v1H9V4a1 1 0 00-2 0v1H6a2 2 0 00-2 2v11a2 2 0 002 2h12a2 2 0 002-2V7a2 2 0 00-2-2h-1V4a1 1 0 00-1-1zM6 7h12v2H6V7zm0 4h12v7H6v-7z"/></svg><span class="screen-reader-text"><?php esc_html_e( 'Sticky post', 'canard' ); ?></span></span>
<?php endif; ?>
<?php
if ( ! has_post_format() ) {
echo '</a>';
} elseif ( has_post_format( 'image' ) || has_post_format( 'gallery' ) ) {
echo '</div>';
}
?>
<?php endif; ?>
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h1>' ); ?>
</header><!-- .entry-header -->
<?php get_template_part( 'entry', 'script' ); ?>
<?php if ( 'post' === $post_type ) : ?>
<div class="entry-meta">
<?php
/*
* Output order: author · date (abbreviated) · comments · categories.
* canard_entry_meta() emits the byline, posted-on, and comments spans.
* canard_entry_categories() emits the cat-links span inline after them.
* Separator slashes between spans are handled by CSS via the
* .content-area .entry-meta > span rules.
*/
canard_entry_meta();
canard_entry_categories();
?>
</div><!-- .entry-meta -->
<?php endif; ?>
<div class="entry-summary">
<?php
/*
* Use the_content() when a <!--more--> tag is present so the "Continue
* reading" link respects the manual break point. Fall back to the_excerpt()
* for posts that have no manual break. get_the_content() is used only for
* the check — actual output always goes through the template tag so
* all registered content filters run.
*
* Cast to string: get_the_content() can return false outside the Loop,
* which would raise a PHP 8 TypeError in str_contains().
*/
if ( str_contains( (string) get_the_content(), '<!--more' ) ) {
the_content(
sprintf(
/* translators: %s: Name of current post. */
wp_kses( __( 'Continue reading %s', 'canard' ), [ 'span' => [ 'class' => [] ] ] ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
)
);
} else {
the_excerpt();
}
?>
</div><!-- .entry-summary -->
</article><!-- #post-## -->