0
我正在PHP中創建一個博客(試圖保持它接近OOP),並認真努力爭取分頁工作在顯示所有帖子的頁面上。在PHP博客分頁
有問題的blog.php的代碼是
<?php
require_once("includes/init.php");
$pagetitle = "Blog";
//include header.
require_once("includes/template/header.php");
// initialise script
$blog = new Blog($db);
$parsedown = new Parsedown();
// load blog posts
$posts = $blog->get_posts();
?>
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Blog Home</h1>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<?php foreach ($posts as $post) { ?>
<h1><a href="<?php echo $post['slug']; ?>"><?php echo $post['title']; ?></a>
</h1>
<p class="lead">by <a href="#"><?php echo $post['author']; ?></a>
</p>
<hr>
<p><i class="fa fa-clock-o"></i> Posted on <?php echo date("d/m/Y", strtotime($post['date'])); ?> At <?php echo date("H:i", strtotime($post['date'])); ?> in <?php
$categories = $blog->get_categories($post['id']);
$links = array();
foreach ($categories as $category) {
$links[] = "<a href='blog-categories.php?id=".$category['category_slug']. "'>".$category['category_name']."</a>";
}
echo implode(", ", $links); ?></p>
<hr>
<p><?php $content = $parsedown->parse($post['content']); echo substr($content,0,445) ; ?></p>
<a class="btn btn-primary" href="<?php echo $post['slug']; ?>">Read More <i class="fa fa-angle-right"></i></a>
<a class="btn btn-primary" href="<?php echo $post['slug']; ?>#disqus_thread"><i class="fa fa-angle-right"></i></a>
<hr>
<?php }
?>
</div>
可能有人請告訴我什麼,我可以添加到博客類或放入一個新的類,允許blog.php的,只顯示第一個說5結果,然後給'下一個'鏈接查看下一組5.我不擔心顯示的總頁數。
真的會很感激這方面的一些幫助,把它拉出我的頭髮。
由於類是訴大,它可以在http://pastebin.com/qN5ii2Ta
你沒有顯示有問題的類,也沒有在你的代碼中顯示任何分頁嘗試。具體來說,你在哪裏執行分頁問題? –
我使用了來自這裏和其他網站的建議進行了幾次分頁嘗試,但是他們中沒有一個似乎真正與我的代碼一起工作,因此爲什麼要問這裏。發佈更新鏈接到課程。 – Railto
這可以幫助你http://www.phpeasystep.com/phptu/29.html – eddwinpaz