-
Notifications
You must be signed in to change notification settings - Fork 0
/
archives.php
255 lines (206 loc) · 7.94 KB
/
archives.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
if(!isset($_REQUEST['date']))
{
header('location: blog.php');
}
else{
$date=$_REQUEST['date'];
$year1=substr($date,0,4);
$month1=substr($date,5,2);
}
?>
<?php include('header.php'); ?>
<?php include_once('config.php'); ?>
<!-- Page Content -->
<div class="container" style="margin-top:10px;">
<div class="row">
<!-- Blog Post Content Column -->
<div class="col-lg-8">
<?Php
/* ===================== Pagination Code Starts ================== */
$adjacents = 7;
$statement = $db->prepare("SELECT * FROM tbl_post where month=? and year=? ORDER BY post_id DESC");
$statement->execute(array($month1,$year1));
$total_pages = $statement->rowCount();
if($total_pages==0)
{
?>
<h1 style="text-align:center;">No Post Found</h1>
<?php
}
$targetpage = $_SERVER['PHP_SELF']; //your file name (the name of this file)
$limit =4; //how many items to show per page
$page = @$_GET['page'];
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0;
$statement = $db->prepare("SELECT * FROM tbl_post where month=? and year=? ORDER BY post_id DESC LIMIT $start, $limit");
$statement->execute(array($month1,$year1));
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1;
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
if ($page > 1)
$pagination.= "<a href=\"$targetpage?date=$date & page=$prev\">« previous</a>";
else
$pagination.= "<span class=\"disabled\">« previous</span>";
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?date=$date & page=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?date=$date & page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?date=$date & page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?date=$date & page=$lastpage\">$lastpage</a>";
}
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?date=$date & page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?date=$date & page=2\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?date=$date & page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?date=$date & page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?date=$date & page=$lastpage\">$lastpage</a>";
}
else
{
$pagination.= "<a href=\"$targetpage?date=$date & page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?date=$date & page=2\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?date=$date & page=$counter\">$counter</a>";
}
}
}
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?date=$date & page=$next\">next »</a>";
else
$pagination.= "<span class=\"disabled\">next »</span>";
$pagination.= "</div>\n";
}
foreach($result as $row)
{
?>
<!-- Blog Post -->
<div class="post">
<!-- Title -->
<h3><?php echo $row['post_title'];?></h3>
<!-- Date/Time -->
<p style="margin-top:5px;"><span class="glyphicon glyphicon-time" ></span> Posted on
<?php
$post_date=$row['post_date'];
$post_day=substr($post_date,8,2);
$post_month=substr($post_date,5,2);
$post_year=substr($post_date,0,4);
if($post_month=='01') {$post_month='Jan';}
if($post_month=='02') {$post_month='Feb';}
if($post_month=='03') {$post_month='Mar';}
if($post_month=='04') {$post_month='Apr';}
if($post_month=='05') {$post_month='May';}
if($post_month=='06') {$post_month='Jun';}
if($post_month=='07') {$post_month='JUL';}
if($post_month=='08') {$post_month='Aug';}
if($post_month=='09') {$post_month='Sep';}
if($post_month=='10') {$post_month='Oct';}
if($post_month=='11') {$post_month='Nov';}
if($post_month=='12') {$post_month='Dec';}
echo $post_day." ".$post_month.", ".$post_year;
?><span class="categories"> Tags : <em>
<?php
//when retrive data (using explode)
$arr=explode(',',$row['tag_id']);
$arr_count=count(explode(',',$row['tag_id']));
$k=0;
$arr1=array();
for($j=0;$j<$arr_count;$j++)
{
$statement1=$db->prepare("select * from tbl_tag where tag_id=?");
$statement1->execute(array($arr[$j]));
$result1=$statement1->fetchAll(PDO::FETCH_ASSOC);
foreach($result1 as $row1)
{
$arr1[$k]=$row1['tag_name'];
}
$k++;
}
$tag_names=implode(",",$arr1);
echo $tag_names;
?>
</em>
</span>
</p>
<hr>
<!-- Preview Image -->
<img src="admin/uploads/<?php echo $row['post_image'];?>" alt="" width="200px" height="150px" style="float:left;padding-right:10px;padding-bottom:7px">
<hr>
<p >
<?php
$pices=explode(" ",$row['post_description']);
$first_page=implode(" ",array_splice($pices,0,95));
$first_page=$first_page."<b> ..........</b>";
?>
<?php
echo $first_page;
?>
</p>
<hr>
<p class="comments">Comments
<span>|</span> <a href="blog2.php?id=<?php echo $row['post_id']; ?>">Continue Reading</a></p><br><br>
</div>
<!--- Blog Post--->
<?php
}
?>
<div class="pagination">
<?php echo $pagination;?>
</div>
</div>
<!-- Blog Sidebar Widgets Column -->
<div class="col-md-1"></div>
<div class="col-md-3">
<!-- Blog Search Well -->
<div class="well">
<div style="width:150px;height:180px;margin:0 auto">
<img class="img-responsive" src="images/2.png" alt="" >
</div>
<h4 style="text-align:center">Masud Kaium</h4>
<!-- /.input-group -->
</div>
<?php include('blog_sidebar.php'); ?>
</div>
<!-- /.row -->
<?php include('footer.php'); ?>