What are some best practices for listing and displaying articles on a PHP CMS website?

When listing and displaying articles on a PHP CMS website, it is important to ensure that the articles are organized and displayed in a user-friendly manner. One best practice is to use pagination to limit the number of articles displayed on each page, improving loading times and user experience.

// Example pagination code snippet
$articlesPerPage = 10;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$offset = ($page - 1) * $articlesPerPage;

// Query to fetch articles with pagination
$query = "SELECT * FROM articles LIMIT $offset, $articlesPerPage";
$result = mysqli_query($connection, $query);

// Display articles
while ($row = mysqli_fetch_assoc($result)) {
    echo "<h2>{$row['title']}</h2>";
    echo "<p>{$row['content']}</p>";
}

// Pagination links
$totalArticles = // Query to get total number of articles
$totalPages = ceil($totalArticles / $articlesPerPage);
for ($i = 1; $i <= $totalPages; $i++) {
    echo "<a href='?page=$i'>$i</a> ";
}