forked from OpenDevelopmentMekong/wp-odm_theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsection-sticky-posts.php
169 lines (164 loc) · 7.02 KB
/
section-sticky-posts.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
162
163
164
165
166
167
168
169
<?php
$filter_by_lang = strtolower(get_the_language_by_language_code(qtrans_getLanguage()));
$tag_name = trim($tag_name);
if (SITE_NAME == "Cambodia"){
$sticky = new WP_Query(array(
'posts_per_page' => 6,
'post__in' => get_option('sticky_posts'),
//'tag' => $tag_name,
'post_type' => 'post',
'language'=> $filter_by_lang,
'post_status' => 'publish',
'caller_get_posts' => 0,
'ignore_sticky_posts' => 1,
'tax_query' => array(
'taxonomy' => 'language',
'field' => 'slug',
'terms' => $filter_by_lang
)
));
}else {
$sticky = new WP_Query(array(
'posts_per_page' => 6,
'post__in' => get_option('sticky_posts'),
//'tag' => $tag_name,
'post_type' => 'post',
'post_status' => 'publish',
'caller_get_posts' => 0,
'ignore_sticky_posts' => 1
));
}
//print_r($sticky);
$number_sticky_post = 0;
$number_two_item_in_column = 0;
$number_item = 0; //count number of posts
?>
<div class="sticky-posts scroll-sticky-posts" id="sticky-tag-<?php echo strtolower($tag_name);?>" data-mcs-theme="dark">
<?php if($sticky->have_posts()) :?>
<?php while($sticky->have_posts()) : $sticky->the_post(); ?>
<?php if (!is_sticky()) continue; ?>
<?php
$number_sticky_post++;
$number_item++;
if($number_item > 1 && $number_item <= 4 ){
$group_sticky_item = " three_per_row";
}else if ($number_item > 4){
$number_two_item_in_column = $number_two_item_in_column +1;
$group_sticky_item = " two_per_row";
$group_sticky_item_index = " two_per_row".$number_two_item_in_column;
}else {
$group_sticky_item = "";
}
?>
<div class="sticky-item<?php echo $group_sticky_item . $group_sticky_item_index; ?>" id="<?php the_ID(); ?>" data-postid="<?php the_ID(); ?>">
<?php show_queried_posts(); ?>
</div>
<?php endwhile; ?>
<?php endif;
wp_reset_query();
?>
<?php
//Query the latest posts to fill the number of maximun number of post, but ignoring sticky post
//$number_latest_post = 6 - $sticky->found_posts;
if (SITE_NAME == "Cambodia"){
$get_latest_post = 100 - $number_sticky_post;
$number_latest_post = 20 - $number_sticky_post;
$latest_post = new WP_Query(array(
'posts_per_page' => $get_latest_post,
'post__not_in' => get_option('sticky_posts'),
'tag' => $tag_name,
'post_type' => 'post',
'post_status' => 'publish',
//'language'=> $filter_by_lang,
'ignore_sticky_posts' => 1,
'caller_get_posts'=> 1,
'tax_query' => array( // Note: using tax_query will get all post from any post type, even the post type is set
array(
'taxonomy' => 'language',
'field' => 'slug',
'terms' => $filter_by_lang
)
)
));
}else {
$number_latest_post = 20 - $number_sticky_post;
$latest_post = new WP_Query(array(
'posts_per_page' => $number_latest_post,
'post__not_in' => get_option('sticky_posts'),
//'tag' => $tag_name,
'post_type' => 'post',
'post_status' => 'publish',
'ignore_sticky_posts' => 1
));
}
?>
<!-- List lastest posts that is not sticky -->
<?php if($latest_post->have_posts()) :?>
<?php while($latest_post->have_posts()) : $latest_post->the_post(); ?>
<?php
if ($number_item < $number_latest_post) {
if (get_post_type() == 'post') {
$number_item++;
if($number_item > 1 && $number_item <= 4 ){
$group_sticky_item = " three_per_row";
}else if ($number_item > 4){
$number_two_item_in_column = $number_two_item_in_column +1;
$group_sticky_item = " two_per_row";
$group_sticky_item_index = " two_per_row".$number_two_item_in_column;
}else {
$group_sticky_item = "";
}
?>
<div class="sticky-item<?php echo $group_sticky_item . $group_sticky_item_index; ?>" id="<?php the_ID(); ?>" data-postid="<?php the_ID(); ?>">
<?php show_queried_posts(); ?>
</div>
<?php
} //if (get_post_type() == 'post')
}else {
break;
}
?>
<?php endwhile; ?>
<?php endif; ?>
</div> <!-- sticky-posts -->
<?php //} //filter_by_tag ?>
<?php function show_queried_posts(){ ?>
<article id="sticky-post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-area">
<header class="post-header">
<?php if(has_post_thumbnail()) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(array(300, 250)); ?>
</a>
</div>
<?php endif; ?>
<a href="<?php the_permalink(); ?>"><h3><?php the_title(); ?></h3></a>
<!--show date and source-->
<?php echo_post_meta(get_post()); ?>
</header>
<section class="post-content">
<?php
if($post->post_excerpt){
the_excerpt();
}
else{
echo odm_excerpt(20, __('Keep reading', 'odm'));
}
?>
</section>
</div>
<footer class="post-actions">
<!-- <a class="button" href="<?php the_permalink(); ?>">
<img src="<?php // echo get_stylesheet_directory_uri()?>/img/info-icon.png"/>
<?php // _e('Read more', 'odm'); ?></a>-->
</footer>
</article>
<?php
}
?>
<script>
(function($) {
$('.sticky-posts .sticky-item:first').addClass('sticky-posts-active');
})(jQuery);
</script>