-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingle.php
More file actions
157 lines (138 loc) · 4 KB
/
single.php
File metadata and controls
157 lines (138 loc) · 4 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
* Single article template
*
* @package laccio
*/
get_header();
while ( have_posts() ) :
the_post();
$cats = get_the_category();
$tags = get_the_tags();
$excerpt = get_the_excerpt();
$post_id = get_the_ID();
?>
<!-- Reading progress bar (CSS scroll-timeline + JS fallback) -->
<div class="reading-progress" id="reading-progress" aria-hidden="true"></div>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'single-article' ); ?>>
<!-- Article header -->
<header class="article-header">
<?php if ( ! empty( $cats ) ) :
$cat = $cats[0];
?>
<a href="<?php echo esc_url( get_category_link( $cat->term_id ) ); ?>" class="cat-label">
<?php echo esc_html( $cat->name ); ?>
</a>
<?php endif; ?>
<h1 class="article-title"><?php the_title(); ?></h1>
<?php if ( $excerpt ) : ?>
<p class="article-subtitle"><?php echo esc_html( $excerpt ); ?></p>
<?php endif; ?>
<?php laccio_the_post_meta(); ?>
<?php laccio_the_reading_time(); ?>
</header>
<!-- Featured image -->
<?php if ( has_post_thumbnail() ) : ?>
<figure class="article-featured-image">
<?php the_post_thumbnail( 'laccio-hero', array(
'loading' => 'eager',
'fetchpriority' => 'high',
'alt' => '',
) ); ?>
<?php
$caption = get_the_post_thumbnail_caption();
if ( $caption ) :
?>
<figcaption><?php echo esc_html( $caption ); ?></figcaption>
<?php endif; ?>
</figure>
<?php endif; ?>
<!-- Article body -->
<div class="article-body">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<nav class="page-links"><span class="page-links-title">' . esc_html__( 'Pàgines:', 'laccio' ) . '</span>',
'after' => '</nav>',
'link_before' => '<span>',
'link_after' => '</span>',
'pagelink' => '%',
'separator' => ' ',
) );
?>
</div>
<!-- Article footer: tags + prev/next nav -->
<footer class="article-footer">
<?php if ( ! empty( $tags ) ) : ?>
<p class="article-tags">
<?php
$tag_links = array_map( function( $tag ) {
return sprintf(
'<a href="%s">%s</a>',
esc_url( get_tag_link( $tag->term_id ) ),
esc_html( $tag->name )
);
}, $tags );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo implode( ', ', $tag_links );
?>
</p>
<?php endif; ?>
<nav class="article-nav" aria-label="<?php esc_attr_e( 'Navegació entre articles', 'laccio' ); ?>">
<div class="nav-prev">
<?php previous_post_link( '%link', '← %title' ); ?>
</div>
<div class="nav-next">
<?php next_post_link( '%link', '%title →' ); ?>
</div>
</nav>
</footer>
</article>
<!-- Related articles -->
<?php
$related = laccio_get_related_posts( $post_id, 3 );
if ( ! empty( $related ) ) :
?>
<div class="related-articles">
<h2 class="section-header"><?php esc_html_e( 'Més sobre aquest tema', 'laccio' ); ?></h2>
<div class="related-list">
<?php foreach ( $related as $rpost ) :
$rpost_id = $rpost->ID;
$rpost_url = get_permalink( $rpost_id );
$rcats = get_the_category( $rpost_id );
?>
<div class="related-item">
<?php if ( ! empty( $rcats ) ) : laccio_the_category_label( $rpost_id ); endif; ?>
<h3 class="related-title">
<a href="<?php echo esc_url( $rpost_url ); ?>">
<?php echo esc_html( get_the_title( $rpost_id ) ); ?>
</a>
</h3>
<?php laccio_the_post_meta( $rpost_id ); ?>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<!-- Comments (behind toggle) -->
<?php
if ( comments_open() || get_comments_number() ) :
?>
<div
class="comments-toggle-section"
style="max-width:680px; margin-inline:auto; padding-inline:1.25rem; margin-bottom:3rem;"
>
<button class="comments-toggle" aria-expanded="false">
<?php
esc_html_e( 'Mostra els comentaris', 'laccio' );
$count = get_comments_number();
if ( $count > 0 ) printf( ' (%d)', (int) $count );
?>
</button>
<div class="comments-container" hidden>
<?php comments_template(); ?>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php get_footer(); ?>