= $title ?>
= $summary ?>
$limit
? mb_substr($text, 0, $limit) . "โฆ"
: $text;
}
function limitBody($text, $limitChars = 500, $id = null) {
$plain = strip_tags($text);
if (mb_strlen($plain) > $limitChars) {
return mb_substr($plain, 0, $limitChars) .
'... See More';
}
return $plain;
}
function withIcon($text, $icons) {
$icon = isset($icons[$text]) ? $icons[$text] . ' ' : '';
return $icon . $text;
}
$categories = ['Property','Vehicle','House','Medical','Restaurants','Business','Electronics','Service','Job Vacancy','Education','Sabun dan Pencuci','Other'];
$typesList = ['Sale','Rent','Wanted','Event','Info','Sponsor','Loan','Other'];
$categoryIcons = [
'Property' => '๐ ',
'Vehicle' => '๐',
'House' => '๐ก',
'Medical' => '๐',
'Restaurants' => '๐ฝ๏ธ',
'Business' => '๐ผ',
'Electronics' => '๐ป',
'Service' => '๐ ๏ธ',
'Job Vacancy' => '๐ผ',
'Education' => '๐',
'Sabun dan Pencuci' => '๐งผ',
'Other' => '๐ฆ'
];
$typeIcons = [
'Sale' => '๐ฐ',
'Rent' => '๐',
'Wanted' => '๐',
'Event' => '๐',
'Info' => 'โน๏ธ',
'Sponsor' => '๐ค',
'Loan' => '๐ธ',
'Other' => '๐ฆ',
];
// GET parameters for filtering
$category = isset($_GET['category']) ? $conn->real_escape_string($_GET['category']) : '';
$type = isset($_GET['type']) ? $conn->real_escape_string($_GET['type']) : '';
$search = isset($_GET['search']) ? $conn->real_escape_string($_GET['search']) : '';
$selectedCategory = $category;
$selectedType = $type;
// --- Pagination for Blog Grid ---
$blogsPerPage = 6;
$totalBlogsRes = $conn->query("SELECT COUNT(*) AS total FROM blogs");
$totalBlogsRow = $totalBlogsRes->fetch_assoc();
$totalBlogs = min($totalBlogsRow['total'], 30); // max 30 blogs
$totalPages = ceil($totalBlogs / $blogsPerPage);
$page = isset($_GET['blogs_page']) ? intval($_GET['blogs_page']) : 1;
if ($page < 1) $page = 1;
if ($page > $totalPages) $page = $totalPages;
$offset = ($page - 1) * $blogsPerPage;
$blogs = $conn->query("SELECT * FROM blogs ORDER BY created_at DESC LIMIT $offset, $blogsPerPage");
// Helper to pick first image
function pickBlogImage($row) {
if (!empty($row['images'])) {
$imgsArray = array_filter(array_map('trim', explode(',', $row['images'])));
if (!empty($imgsArray)) return $imgsArray[0];
}
if (!empty($row['image'])) return $row['image'];
if (!empty($row['content'])) {
if (preg_match('/]+src="([^"]+)"/i', $row['content'], $matches)) return $matches[1];
}
return 'default.jpg';
}
?>
No entries found.
"; endif; // --- Total rows for Entries Pagination --- $totalSql = "SELECT COUNT(*) AS total FROM entries WHERE 1=1"; $paramsTotal = []; $typesTotal = ''; if($category) { $totalSql .= " AND category = ?"; $paramsTotal[] = $category; $typesTotal .= 's'; } if($type) { $totalSql .= " AND type = ?"; $paramsTotal[] = $type; $typesTotal .= 's'; } if($search) { $totalSql .= " AND (title LIKE ? OR content LIKE ?)"; $paramsTotal[] = "%$search%"; $paramsTotal[] = "%$search%"; $typesTotal .= 'ss'; } $stmtTotal = $conn->prepare($totalSql); if ($paramsTotal) { $stmtTotal->bind_param($typesTotal, ...$paramsTotal); } $stmtTotal->execute(); $totalRes = $stmtTotal->get_result(); $totalRows = ($totalRes && $row = $totalRes->fetch_assoc()) ? $row['total'] : 0; $totalPages = ceil($totalRows / $entriesLimit); // --- Output Entries Pagination --- if ($totalPages > 1): echo 'No blogs found.
"; endif; ?>