-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloop-blog.php
125 lines (110 loc) · 4.88 KB
/
loop-blog.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
125
<?php function render_post( $page, $index, $post_id ){ ?>
<!-- post thumbnail -->
<?php
$is_external = false;
$link_url = get_post_meta( $post_id, 'resource_url', true );
if ( empty( $link_url ) ){
$link_url = get_post_permalink( $post_id );
}
else{
$is_external = true;
}
$dominant_color = get_post_meta( $post_id, 'dominant_color', true );
$dominant_color_css = str_replace( '[', 'background-color:rgb( ', $dominant_color );
$dominant_color_css = str_replace( ']', ' )', $dominant_color_css );
?>
<div class="blog-post-thumbnail post-thumbnail post-thumbnail-<?php echo $page; ?>-<?php echo $index; ?>" style="<?php echo $dominant_color_css; ?>">
<a href="<?php echo $link_url; ?>" title="<?php get_the_title(); ?>">
<img class="post-thumbnail-img lazy-load"
src="<?php echo get_the_post_thumbnail_url( $post_thumbnail_id, 'medium_large' ); ?>"
data-src="<?php echo get_the_post_thumbnail_url( $post_thumbnail_id, 'medium_large' ); ?>"
>
<!-- post title -->
<p class="post-thumbnail-title">
<?php
the_title();
$post_date = get_the_time('F j, Y');
$post_date_full = $post_date . ' ' . get_the_time('g:i a');
$post_author = get_the_author();
global $coauthors_plus;
$coauthors = get_coauthors();
$author_id = $coauthor[0]->data->ID;
$author_email = esc_attr( get_the_author_meta( 'email', $author_id ) );
$profile_img_url = esc_attr( get_avatar_url( $author_email, array( 'size' => 22 ) ) );
if ( class_exists( 'Moment\Moment' ) ){
$m = new \Moment\Moment($post_date);
$post_date_ago = $m->fromNow()->getRelative();
echo " <span class='post-thumbnail-date'><img width=\"22\" height=\"22\" loading=\"lazy\" class=\"lazy-load u-photo rounded-circle mr-2\" src=\"$profile_img_url\" data-src=\"$profile_img_url\"> $post_author | $post_date_ago</span>";
}
?>
</p>
<!-- /post title -->
</div>
</a>
<!-- /post thumbnail -->
<?php } ?>
<div class="container">
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<?php
$index = $wp_query->current_post + 1;
$page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
if ( $page === 1 && $index === 1 ){ ?>
<div class="row">
<div class="col-sm-12 col-md-8 text-center m-0 p-1">
<?php render_post( $page, $index, $post->ID ); ?>
</div>
<?php } elseif ( $page !== 1 && $index === 1 ) { ?>
<div class="row">
<div class="col-sm-12 col-md-4 text-center p-1 m-0">
<?php render_post( $page, $index, $post->ID ); ?>
</div>
<?php } elseif ( $page === 1 && $index === 2 ) { ?>
<div class="col-sm-12 col-md-4">
<div class="row">
<div class="col-sm-12 text-center m-0 p-1">
<?php render_post( $page, $index, $post->ID ); ?>
</div>
<?php } elseif ( $page === 1 && $index === 3 ) { ?>
<div class="col-sm-12 text-center m-0 p-1">
<?php render_post( $page, $index, $post->ID ); ?>
</div>
</div>
</div>
</div>
<?php } elseif ( $page === 1 && $index === 4 ) { ?>
<div class="row">
<div class="col-sm-12 col-md-6 col-lg-6 text-center p-1 m-0">
<?php render_post( $page, $index, $post->ID ); ?>
</div>
<?php } elseif ( $page === 1 && in_array( $index, [5, 6, 7 ] ) ) { ?>
<div class="col-sm-12 col-md-6 col-lg-6 text-center p-1 m-0">
<?php render_post( $page, $index, $post->ID ); ?>
</div>
<?php } elseif ( $page === 1 && $index > $wp_query->post_count - 8 && $index < $wp_query->post_count ) { ?>
<div class="col-sm-12 col-md-6 col-lg-3 text-center p-1 m-0">
<?php render_post( $page, $index, $post->ID ); ?>
</div>
<?php } elseif ( $page === 1 && $index === $wp_query->post_count ) { ?>
<div class="col-sm-12 col-md-6 col-lg-3 text-center p-1 m-0">
<?php render_post( $page, $index, $post->ID ); ?>
</div>
</div>
<?php } elseif ( $page === 1 && $index < 8 ) { ?>
<div class="col-sm-12 col-md-6 col-lg-6 text-center p-1 m-0">
<?php render_post( $page, $index, $post->ID ); ?>
</div>
<?php } else { ?>
<div class="col-sm-12 col-md-4 text-center p-1 m-0">
<?php render_post( $page, $index, $post->ID ); ?>
</div>
<?php }
?>
<?php endwhile; ?>
</div>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'botwiki' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>