-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthor.php
161 lines (152 loc) · 5.2 KB
/
author.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
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
158
159
160
161
<?php
get_header();
$author_id = get_the_author_meta('ID');
?>
<div class="container author-page">
<h1 class="profile-header text-center"><?php the_author_meta('nickname'); ?> Page</h1>
<div class="author-main-info">
<div class="row">
<div class="col-md-3">
<?php
$avatar_ars = array(
'class' => 'img-responsive img-thumbnail'
);
echo get_avatar($author_id, 196, '', 'User Avatar', $avatar_ars);
?>
</div>
<div class="col-md-9">
<ul class="list-unstyled author-names">
<li><span>First Name:</span> <?php the_author_meta('first_name');?></li>
<li><span>Last Name:</span> <?php the_author_meta('last_name');?></li>
<li><span>Nickname:</span> <?php the_author_meta('nickname');?></li>
</ul>
<hr>
<?php if (get_the_author_meta('description')) { ?>
<p>
<?php the_author_meta('description');?>
</p>
<?php } else {
echo '<p>There\'s no biography</p>';
} ?>
</div>
</div> <!-- End row -->
</div> <!-- End author-main-info -->
<div class="row author-stats">
<div class="col-md-3">
<div class="stats">
Posts Count
<span><?php echo count_user_posts( $author_id ) ?></span>
</div>
</div>
<div class="col-md-3">
<div class="stats">
Comments Count
<span>
<?php
$comments_count_args = array(
'user_id' => $author_id,
'count' => true
);
echo get_comments($comments_count_args);
?>
</span>
</div>
</div>
<div class="col-md-3">
<div class="stats">
Total Posts View
<span>0</span>
</div>
</div>
<div class="col-md-3">
<div class="stats">
Testing
<span>0</span>
</div>
</div>
</div> <!-- End row -->
<?php
$author_posts_per_page = 5;
$author_posts_args = array(
'author' => $author_id,
'posts_per_page' => $author_posts_per_page
);
$posts_query = new WP_Query($author_posts_args);
?>
<?php if ($posts_query->have_posts()) : // check if there's posts ?>
<h3 class="text-center author-posts-title">
<?php
// check if author posts count >= author posts per page count
if (count_user_posts($author_id) >= $author_posts_per_page) { ?>
Latest <?php echo $author_posts_per_page; ?> Posts
<?php } else ?>
Latest Posts
</h3> <!-- End author-posts-title -->
<?php while ($posts_query->have_posts()) : // loop through posts
$posts_query->the_post(); // set up the current post ?>
<div class="row author-posts">
<div class="col-sm-3">
<?php the_post_thumbnail( '', [
'class' => 'img-fluid img-thumbnail d-block',
'title' => get_the_title()
]); ?>
</div> <!-- End col-sm-3 -->
<div class="col-sm-9">
<h3 class="post-title">
<a href="<?php the_permalink(); ?>">
<?php the_title()?>
</a>
</h3>
<span class="post-date"><i class="far fa-calendar-alt"></i> <?php the_time('F j, Y'); ?>, </span>
<span class="post-comments"><i class="far fa-comments"></i> <?php comments_popup_link(); ?></span>
<div class="post-content"><?php the_excerpt(); ?></div>
</div> <!-- End col-sm-9 -->
</div> <!-- End author-posts -->
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); // restores the $post global to the current post in the main query. ?>
<?php
$comments_per_page = 5;
$comments_args = array(
'user_id' => $author_id,
'status' => 'approve',
'number' => $comments_per_page,
'post_status' => 'publish',
'post_type' => 'post'
);
$comments = get_comments($comments_args);
$comments_count_args = array(
'user_id' => $author_id,
'count' => true
);
if ($comments) : // check if there is any comments ?>
<h3 class="text-center author-comments-title">
<?php
if (get_comments($comments_count_args) >= $comments_per_page) { ?>
Latest <?php echo $comments_per_page; ?> Comments
<?php } else { ?>
Latest Comments
<?php } ?>
</h3> <!-- End author-comments-title -->
<?php foreach ($comments as $comment) : ?>
<div class="author-comments">
<h3 class="post-title">
<a href="<?php echo get_permalink($comment->comment_post_ID) ?>">
<?php echo get_the_title($comment->comment_post_ID) ?>
</a>
</h3>
<span class="comment-date">
<i class="far fa-calendar-alt"></i> Added On <?php echo mysql2date( 'D, F j, Y', $comment->comment_date ); ?>
</span>
<div class="comment-content">
<?php echo $comment->comment_content; ?>
</div>
</div> <!-- End author-comments -->
<?php endforeach; ?>
<?php
else :
echo 'This author don\'t have any comments';
endif; ?>
</div> <!-- End author-page container -->
<div style="margin-bottom:60px"></div>
<?php get_footer(); ?>