1+ <?php
2+ include "core.php " ;
3+ head ();
4+
5+ $ queryst = mysqli_query ($ connect , "SELECT date_format FROM `settings` LIMIT 1 " );
6+ $ rowst = mysqli_fetch_assoc ($ queryst );
7+
8+ $ category_id = (int ) $ _GET ['id ' ];
9+ $ runq = mysqli_query ($ connect , "SELECT * FROM `categories` WHERE id=' $ category_id' " );
10+ $ rw = mysqli_fetch_assoc ($ runq );
11+
12+ if (empty ($ category_id )) {
13+ echo '<meta http-equiv="refresh" content="0; url=blog.php"> ' ;
14+ exit ();
15+ }
16+
17+ if (mysqli_num_rows ($ runq ) == 0 ) {
18+ echo '<meta http-equiv="refresh" content="0; url=blog.php"> ' ;
19+ exit ();
20+ }
21+ ?>
22+ <div class="col-md-8">
23+
24+ <div class="card">
25+ <div class="card-header"><i class="far fa-file-alt"></i> Blog - <?php
26+ echo $ rw ['category ' ];
27+ ?> </div>
28+ <div class="card-body">
29+
30+ <?php
31+ $ postsperpage = 6 ;
32+
33+ $ pageNum = 1 ;
34+ if (isset ($ _GET ['page ' ])) {
35+ $ pageNum = $ _GET ['page ' ];
36+ }
37+ if (!is_numeric ($ pageNum )) {
38+ echo '<meta http-equiv="refresh" content="0; url=blog.php"> ' ;
39+ exit ();
40+ }
41+ $ rows = ($ pageNum - 1 ) * $ postsperpage ;
42+
43+ $ run = mysqli_query ($ connect , "SELECT * FROM `posts` WHERE category_id=' $ category_id' and active='Yes' ORDER BY id DESC LIMIT $ rows, $ postsperpage " );
44+ $ count = mysqli_num_rows ($ run );
45+ if ($ count <= 0 ) {
46+ echo '<div class="alert alert-info">There are no published posts</div> ' ;
47+ } else {
48+ while ($ row = mysqli_fetch_assoc ($ run )) {
49+
50+ $ image = "" ;
51+ if ($ row ['image ' ] != "" ) {
52+ $ image = '<img src=" ' . $ row ['image ' ] . '" alt=" ' . $ row ['title ' ] . '" class="card-img-top" width="100%" height="225""> ' ;
53+ } else {
54+ $ image = '<svg class="bd-placeholder-img card-img-top" width="100%" height="225" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: Thumbnail" preserveAspectRatio="xMidYMid slice" focusable="false">
55+ <title>No Image</title><rect width="100%" height="100%" fill="#55595c"/>
56+ <text x="46%" y="50%" fill="#eceeef" dy=".3em">No Image</text></svg> ' ;
57+ }
58+
59+ echo '
60+ <div class="card shadow-sm">
61+ <a href="post.php?id= ' . $ row ['id ' ] . '">
62+ ' . $ image .'
63+ </a>
64+ <div class="card-body">
65+ <a href="post.php?id= ' . $ row ['id ' ] . '">
66+ <h5 class="card-title"> ' . $ row ['title ' ] . '</h5>
67+ </a>
68+ <div class="d-flex justify-content-between align-items-center">
69+ <a href="category.php?id= ' . $ row ['category_id ' ] . '">
70+ <span class="badge bg-primary"> ' . post_category ($ row ['category_id ' ]) . '</span>
71+ </a>
72+ <small><i class="fas fa-comments"></i> Comments:
73+ <a href="post.php?id= ' . $ row ['id ' ] . '#comments" class="blog-comments">
74+ <strong> ' . post_commentscount ($ row ['id ' ]) . '</strong>
75+ </a>
76+ </small>
77+ </div>
78+ <p class="card-text"> ' . short_text (strip_tags (html_entity_decode ($ row ['content ' ])), 400 ) . '</p>
79+ <div class="d-flex justify-content-between align-items-center">
80+ <b><i class="fas fa-user-edit"></i> ' . post_author ($ row ['author_id ' ]) . '</b>
81+ <small class="text-muted">
82+ <i class="far fa-calendar-alt"></i> ' . date ($ rowst ['date_format ' ], strtotime ($ row ['date ' ])) . ', ' . $ row ['time ' ] . '
83+ </small>
84+ </div>
85+ </div>
86+ </div><br />
87+ ' ;
88+ }
89+
90+ $ query = "SELECT COUNT(id) AS numrows FROM posts WHERE category_id=' $ category_id' and active='Yes' " ;
91+ $ result = mysqli_query ($ connect , $ query );
92+ $ row = mysqli_fetch_array ($ result );
93+ $ numrows = $ row ['numrows ' ];
94+ $ maxPage = ceil ($ numrows / $ postsperpage );
95+
96+ $ pagenums = '' ;
97+
98+ echo '<center> ' ;
99+
100+ for ($ page = 1 ; $ page <= $ maxPage ; $ page ++) {
101+ if ($ page == $ pageNum ) {
102+ $ pagenums .= "<a href='?id= $ category_id&page= $ page' class='btn btn-primary'> $ page</a> " ;
103+ } else {
104+ $ pagenums .= "<a href= \"?id= $ category_id&page= $ page \" class='btn btn-default'> $ page</a> " ;
105+ }
106+ }
107+
108+ if ($ pageNum > 1 ) {
109+ $ page = $ pageNum - 1 ;
110+ $ previous = "<a href= \"?id= $ category_id&page= $ page \" class='btn btn-default'><i class='fa fa-arrow-left'></i> Previous</a> " ;
111+
112+ $ first = "<a href= \"?id= $ category_id&page=1 \" class='btn btn-default'><i class='fa fa-arrow-left'\></i> <i class='fa fa-arrow-left'></i> First</a> " ;
113+ } else {
114+ $ previous = ' ' ;
115+ $ first = ' ' ;
116+ }
117+
118+ if ($ pageNum < $ maxPage ) {
119+ $ page = $ pageNum + 1 ;
120+ $ next = "<a href= \"?id= $ category_id&page= $ page \" class='btn btn-default'><i class='fa fa-arrow-right'></i> Next</a> " ;
121+
122+ $ last = "<a href= \"?id= $ category_id&page= $ maxPage \" class='btn btn-default'><i class='fa fa-arrow-right'></i> <i class='fa fa-arrow-r'></i> Last</a> " ;
123+ } else {
124+ $ next = ' ' ;
125+ $ last = ' ' ;
126+ }
127+
128+ echo $ first . $ previous . $ pagenums . $ next . $ last ;
129+
130+ echo '</center> ' ;
131+ }
132+ ?>
133+
134+ </div>
135+ </div>
136+
137+ </div>
138+ <?php
139+ sidebar ();
140+ footer ();
141+ ?>
0 commit comments