193 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
		
		
			
		
	
	
			193 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
|   | <!DOCTYPE html> | |||
|  | <html> | |||
|  | <head> | |||
|  |     <?php | |||
|  | 
 | |||
|  | 
 | |||
|  |     // 设置博客首页的SEO信息
 | |||
|  |     $title = "博客 - AI工具导航与最新AI新闻 - AI Tool Path"; | |||
|  |     $description = "访问我们的博客,获取最新的AI工具、技术趋势、行业动态与AI新闻,帮助您快速了解和使用AI技术。"; | |||
|  |     $keywords = "AI博客, 人工智能新闻, AI工具, AI技术趋势, AI行业动态"; | |||
|  | 
 | |||
|  |     // 引入包含SEO标签的文件
 | |||
|  |     include('container/links.php'); | |||
|  |     ?>
 | |||
|  | </head> | |||
|  | 
 | |||
|  | <body class="body-bg-color"> | |||
|  |     <!-- Header --> | |||
|  |     <?php include 'container/header.php'; ?>
 | |||
|  | 
 | |||
|  |     <!-- Page Title Start --> | |||
|  |     <section class="page-title"> | |||
|  |         <div class="container"> | |||
|  |             <div class="page-title__inner"> | |||
|  |                 <div class="page-title__shape-1" style="background-image: url(images/shapes/page-title-shape-1.png);"></div> | |||
|  |                 <div class="page-title__title-box"> | |||
|  |                     <p class="page-title__sub-title">博客文章</p> | |||
|  |                     <h3 class="page-title__title">查看我们的文章,这可能有助于您开始 AI 之旅。</h3> | |||
|  |                 </div> | |||
|  |                 <p class="page-title__text">掌握 AI 工具的艺术:释放其强大力量 <br> 利用 AI 工具路径实现自动化创造力</p> | |||
|  |             </div> | |||
|  |         </div> | |||
|  |     </section> | |||
|  |     <style> | |||
|  |         .active { | |||
|  |             background: #426bff;
 | |||
|  |             border-radius: 4px; | |||
|  |         } | |||
|  |         .active a { | |||
|  |             background: #426bff;
 | |||
|  |             color: #fff !important;
 | |||
|  |         } | |||
|  |     </style> | |||
|  |     <!-- Page Title End --> | |||
|  | 
 | |||
|  |     <!-- Blog Page Start --> | |||
|  |     <section class="blog-page"> | |||
|  |         <div class="container"> | |||
|  |             <div class="row"> | |||
|  |                 <?php | |||
|  |                 // 设置每页显示的博客数量
 | |||
|  |                 $blogs_per_page = 9; | |||
|  | 
 | |||
|  |                 // 获取当前页码,默认是1
 | |||
|  |                 $current_page = isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] > 0 ? (int)$_GET['page'] : 1; | |||
|  | 
 | |||
|  |                 // 计算 SQL 查询的起始行
 | |||
|  |                 $start = ($current_page - 1) * $blogs_per_page; | |||
|  | 
 | |||
|  |                 // 计算总博客数
 | |||
|  |                 $total_blogs_query = "SELECT COUNT(*) as total FROM cn_blogs WHERE status = 1"; | |||
|  |                 $total_blogs_result = mysqli_query($conn, $total_blogs_query); | |||
|  | 
 | |||
|  |                 if (!$total_blogs_result) { | |||
|  |                     header('Location: 404'); // 查询失败,重定向到404页面
 | |||
|  |                     exit(); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 $total_blogs_row = mysqli_fetch_assoc($total_blogs_result); | |||
|  |                 $total_blogs = intval($total_blogs_row['total']); | |||
|  |                 $total_pages = ceil($total_blogs / $blogs_per_page); | |||
|  | 
 | |||
|  |                 // 获取当前页的博客列表
 | |||
|  |                 $blogs_query = "SELECT id, title, image, created_at FROM cn_blogs WHERE status = 1 ORDER BY created_at DESC LIMIT ?, ?"; | |||
|  |                 $stmt = $conn->prepare($blogs_query); | |||
|  |                 $stmt->bind_param('ii', $start, $blogs_per_page); | |||
|  |                 $stmt->execute(); | |||
|  |                 $result = $stmt->get_result(); | |||
|  | 
 | |||
|  |                 if (!$result) { | |||
|  |                     header('Location: 404'); // 查询失败,重定向到404页面
 | |||
|  |                     exit(); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 // 显示博客
 | |||
|  |                 while ($blog = $result->fetch_assoc()) { | |||
|  |                     $id = $blog['id']; | |||
|  |                     $title = htmlspecialchars($blog['title'], ENT_QUOTES, 'UTF-8'); | |||
|  |                     $image_name = htmlspecialchars($blog['image'], ENT_QUOTES, 'UTF-8'); | |||
|  |                     $created_at = new DateTime($blog['created_at']); | |||
|  |                     $formatted_date = $created_at->format('d M Y'); | |||
|  |                     $read_time = '2 Minute Read'; | |||
|  | 
 | |||
|  |                     echo "
 | |||
|  |                     <div class='col-xl-4 col-lg-4 col-md-6'> | |||
|  |                         <div class='blog-page__single'> | |||
|  |                             <div class='blog-page__img-box'> | |||
|  |                                 <div class='blog-page__img'> | |||
|  |                                     <img src='$image_name' alt=''> | |||
|  |                                 </div> | |||
|  |                             </div> | |||
|  |                             <h3 class='blog-page__title'> | |||
|  |                                 <a href='blog-details?blog=$id'>$title</a> | |||
|  |                             </h3> | |||
|  |                         </div> | |||
|  |                     </div>";
 | |||
|  |                 } | |||
|  |                 ?>
 | |||
|  |             </div> | |||
|  | 
 | |||
|  |             <!-- Pagination --> | |||
|  |             <div class="career-page__pagination mt-5"> | |||
|  |                 <ul class="pg-pagination list-unstyled"> | |||
|  |                     <?php | |||
|  |                     // 基础URL设置
 | |||
|  |                     $base_url = htmlspecialchars("?page="); | |||
|  | 
 | |||
|  |                     // "Previous"按钮
 | |||
|  |                     if ($current_page > 1): ?>
 | |||
|  |                         <li class="prev"> | |||
|  |                             <a href="<?php echo $base_url . ($current_page - 1); ?>" aria-label="Previous"> | |||
|  |                                 <span class="fas fa-arrow-left"></span> | |||
|  |                             </a> | |||
|  |                         </li> | |||
|  |                     <?php endif; ?>
 | |||
|  | 
 | |||
|  |                     <?php if ($total_pages <= 6): ?>
 | |||
|  |                         <!-- 如果总页数小于等于6,则显示所有页码 --> | |||
|  |                         <?php for ($page = 1; $page <= $total_pages; $page++): ?>
 | |||
|  |                             <li class="count <?php echo $page == $current_page ? 'active' : ''; ?>"> | |||
|  |                                 <a href="<?php echo $base_url . $page; ?>"><?php echo $page; ?></a>
 | |||
|  |                             </li> | |||
|  |                         <?php endfor; ?>
 | |||
|  |                     <?php else: ?>
 | |||
|  |                         <!-- 显示第一页和第二页 --> | |||
|  |                         <li class="count <?php echo $current_page == 1 ? 'active' : ''; ?>"> | |||
|  |                             <a href="<?php echo $base_url . '1'; ?>">1</a> | |||
|  |                         </li> | |||
|  |                         <li class="count <?php echo $current_page == 2 ? 'active' : ''; ?>"> | |||
|  |                             <a href="<?php echo $base_url . '2'; ?>">2</a> | |||
|  |                         </li> | |||
|  | 
 | |||
|  |                         <!-- 中间省略部分 --> | |||
|  |                         <?php if ($current_page > 4): ?>
 | |||
|  |                             <li class="count"><span>...</span></li> | |||
|  |                         <?php endif; ?>
 | |||
|  | 
 | |||
|  |                         <!-- 显示中间的页码 --> | |||
|  |                         <?php | |||
|  |                         $start_page = max(3, $current_page - 2); | |||
|  |                         $end_page = min($total_pages - 2, $current_page + 2); | |||
|  | 
 | |||
|  |                         for ($page = $start_page; $page <= $end_page; $page++): ?>
 | |||
|  |                             <li class="count <?php echo $page == $current_page ? 'active' : ''; ?>"> | |||
|  |                                 <a href="<?php echo $base_url . $page; ?>"><?php echo $page; ?></a>
 | |||
|  |                             </li> | |||
|  |                         <?php endfor; ?>
 | |||
|  | 
 | |||
|  |                         <!-- 最后两页 --> | |||
|  |                         <li class="count <?php echo $current_page == $total_pages - 1 ? 'active' : ''; ?>"> | |||
|  |                             <a href="<?php echo $base_url . ($total_pages - 1); ?>"><?php echo $total_pages - 1; ?></a>
 | |||
|  |                         </li> | |||
|  |                         <li class="count <?php echo $current_page == $total_pages ? 'active' : ''; ?>"> | |||
|  |                             <a href="<?php echo $base_url . $total_pages; ?>"><?php echo $total_pages; ?></a>
 | |||
|  |                         </li> | |||
|  |                     <?php endif; ?>
 | |||
|  | 
 | |||
|  |                     <!-- "Next"按钮 --> | |||
|  |                     <?php if ($current_page < $total_pages): ?>
 | |||
|  |                         <li class="next"> | |||
|  |                             <a href="<?php echo $base_url . ($current_page + 1); ?>" aria-label="Next"> | |||
|  |                                 <span class="fas fa-arrow-right"></span> | |||
|  |                             </a> | |||
|  |                         </li> | |||
|  |                     <?php endif; ?>
 | |||
|  |                 </ul> | |||
|  |             </div> | |||
|  |         </div> | |||
|  |     </section> | |||
|  |     <!-- Blog Page End --> | |||
|  | 
 | |||
|  |     <!-- Free Trail Start --> | |||
|  |     <?php include 'container/free_trail.php'; ?>
 | |||
|  |     <!-- Free Trail End --> | |||
|  | 
 | |||
|  |     <!-- Main Footer Start --> | |||
|  |     <?php include 'container/footer.php'; ?>
 | |||
|  |     <!-- Main Footer End --> | |||
|  | 
 | |||
|  |     <?php include 'container/footer_links.php'; ?>
 | |||
|  | </body> | |||
|  | </html> |