-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticles.php
More file actions
127 lines (103 loc) · 4.79 KB
/
articles.php
File metadata and controls
127 lines (103 loc) · 4.79 KB
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
<?php
require "includes/config.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?php echo $config['title']; ?></title>
<!-- Bootstrap Grid -->
<link rel="stylesheet" type="text/css" href="/media/assets/bootstrap-grid-only/css/grid12.css">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet">
<!-- Custom -->
<link rel="stylesheet" type="text/css" href="/media/css/style.css">
</head>
<body>
<div id="wrapper">
<?php include "includes/header.php";?>
<div id="content">
<div class="container">
<div class="row">
<section class="content__left col-md-8">
<div class="block">
<h3>Навигация по всем записям</h3>
<div class="block__content">
<div class="articles articles__horizontal">
<?php
$per_page = 4;
$page = 1;
if(isset($_GET['page']))
{
$page = (int)$_GET['page'];
}
$total_count_q = mysqli_query($connection, "SELECT COUNT(`id`) AS `total_count` FROM `articles`");
$total_count = mysqli_fetch_assoc($total_count_q);
$total_count = $total_count['total_count'];
$total_pages = ceil($total_count / $per_page);
if($page < 1 || $page > $total_pages){
$page = 1;
}
$offset = ($per_page*$page) - $per_page;
$articles = mysqli_query($connection, "SELECT * FROM `articles` ORDER BY `id` DESC LIMIT $offset,$per_page");
$articles_exist = true;
if(mysqli_num_rows($articles) <= 0){
echo "Записей пока нет!";
$articles_exist = false;
}
?>
<?php
while($art = mysqli_fetch_assoc($articles)) {
?>
<article class="article">
<div class="article__image"
style="background-image: url(/static/images/<?php echo $art['image']; ?>);"></div>
<div class="article__info">
<a href="/article.php?id=<?php echo $art['id']; ?>"><?php echo $art['title']; ?></a>
<div class="article__info__meta">
<?php
$art_cat = false;
foreach ($categories as $cat) {
if ($cat['id'] == $art['categories_id']) {
$art_cat = $cat;
break;
}
}
?>
<small>Категория: <a
href="pages/cat<?php echo $art_cat['id'] ?>.php"><?php echo $art_cat['title']; ?></a>
</small>
</div>
<div class="article__info__preview"><?php echo mb_substr(strip_tags($art['text']), 0, 100, 'utf-8')." ..."; ?></div>
</div>
</article>
<?php
}
?>
</div>
<?php
if($articles_exist == true)
{
echo '<div class="paginator">';
if($page > 1){
echo '<a href="/articles.php?page='.($page-1).'"> « Прошлая страница </a> ' ;
}
if($page < $total_pages){
echo '<a href="/articles.php?page='.($page+1).'"> Следующая страница » </a> ' ;
}
echo '</div>';
}
?>
</div>
</div>
</section>
<section class="content__right col-md-4">
<?php include "includes/sidebar.php"; ?>
</section>
</div>
</div>
</div>
<?php include "includes/footer.php"; ?>
</div>
</body>
</html>