-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsidebar.php
81 lines (79 loc) · 2.14 KB
/
sidebar.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
<?php
// get category comments count
$comments_args = array(
'status' => 'approve'
);
$comments_count = 0;
$all_comments = get_comments($comments_args); // get all comments
foreach ($all_comments as $comment) {
$post_id = $comment->comment_post_ID; // get comment post ID
if (in_category( 'programming', $post_id )) { // check if post not in programming category
$comments_count++;
}
}
$cat = get_queried_object();
$posts_count = $cat->count;
?>
<div class="sidebar-programming">
<div class="widget">
<h3 class="widget-title"><?php single_tag_title() ?> Statistics</h3>
<div class="widget-content">
<ul>
<li>
<span>Comments Count</span>: <?php echo $comments_count ?>
</li>
<li>
<span>Articles Count</span>: <?php echo $posts_count ?>
</li>
</ul>
</div>
</div>
<div class="widget">
<h3 class="widget-title">Latest Learning Posts</h3>
<div class="widget-content">
<ul>
<?php
$posts_args = array(
'posts_per_page' => 5,
'cat' => 8
);
$query = new WP_Query($posts_args);
if ($query->have_posts()) :
while ($query->have_posts()) :
$query->the_post(); ?>
<li>
<a target="_blank" href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile;
wp_reset_postdata();
endif; ?>
</ul>
</div>
</div>
<div class="widget">
<h3 class="widget-title">Most Active Posts</h3>
<div class="widget-content">
<ul>
<?php
$hot_posts_args = array(
'posts_per_page' => 2,
'orderby' => 'comment_count'
);
$hot_query = new WP_Query($hot_posts_args);
if ($hot_query->have_posts()) :
while ($hot_query->have_posts()) :
$hot_query->the_post(); ?>
<li>
<a target="_blank" href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile;
wp_reset_postdata();
endif; ?>
</ul>
</div>
</div>
</div>