-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
124 lines (120 loc) · 3.5 KB
/
index.php
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
<?php
/**
* Blogs
**/
get_header();
get_template_part( 'parts/navigation' );
?>
<style>
.blog_title{
padding-top: 2rem;
padding-bottom:2rem;
background: var(--main_colour);
color: var(--white_tone);
}
.blog_link{
color: var(--main_colour);
text-decoration: none;
}
.blog_space{
padding-top: 2rem;
padding-bottom: 2rem;
}
.blog_grid{
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 1rem;
}
.post__header {
border: 2px solid #ccc;
position: relative;
padding: 0 1rem;
background: #fff;
align-items: center;
border-radius: 1rem;
gap: 0.5rem;
box-shadow: 0px 12px 18px -6px rgba(0, 0, 0, 0.3);
}
.post__header:hover {
border: 2px solid var(--main_colour);
}
.page-title{
font-size: 2.5rem;
}
@media(orientation: portrait){
.blog_grid{
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 1rem;
}
}
</style>
<?php if ( is_home() && ! is_front_page() && ! empty( single_post_title( '', false ) ) ) : ?>
<section class="blog_title">
<header class="container">
<h1 class="page-title"><?php single_post_title(); ?></h1>
</header>
</section>
<?php endif; ?>
<div class="container blog_space">
<div class="blog_grid">
<?php
// set up the arguments for the query to select the main post
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 20
);
// create a new WP_Query instance with the arguments
$query = new WP_Query( $args );
// start the loop
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
?>
<article class="d-flex">
<div>
<?php
if (has_post_thumbnail()): ?>
<a href="<?php the_permalink(); ?>">
<div class="img-wrapper_first-post">
<div class="post__thumbnail">
<?php if (has_post_thumbnail()) :
$thumbnail_id = get_post_thumbnail_id(); // Get the ID of the post thumbnail
$thumbnail = wp_get_attachment_image($thumbnail_id, 'medium_large', false, array('class' => 'post__thumbnail')); // Get the HTML for the post thumbnail without lazy loading
?>
<?php echo $thumbnail; ?>
<?php endif; ?>
</div>
</div>
</a>
<?php
endif;
?>
<header class="post__header p-2" role="heading">
<h2 class="fs-2">
<a class="blog_link" href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<p class="post__date"><time><?php echo human_time_diff(strtotime($post->post_date)) . ' ' . __('ago'); ?></time></p>
<p class="fc-5">
<?php
$excerpt = get_the_excerpt();
$excerpt = wp_trim_words( $excerpt, 20, '...' );
echo $excerpt;
?>
</p>
</header>
</div>
</article>
<?php
endwhile;
endif;
?>
</div>
</div>
<?php
// reset the query
wp_reset_postdata();
get_footer();
?>