我顯示與新聞箱。每個盒子都來自不同的類別。帶有一個主要帖子的介紹塊和介紹和幾個僅鏈接
這裏是什麼,我盡力去完成的截圖:
Display boxes with news from every category
但只檢查設計,讓PHP代碼。這是過時的問題。 (對不起,把這個鏈接,但我不能附加圖像,低分)
後主試圖顯示其餘的新聞,但我只能顯示主要職位,之後列出的職位在第一篇文章是重複的。
這裏是我的代碼:
public function category_box($category_id, $category_name) {
$this->_db->query("SELECT * from posts WHERE category_id = '$category_id'");
$this->current_category_posts = $this->_db->resultset();
$posts = array();
foreach ($this->current_category_posts as $post) {
if ($post['category_id'] === $category_id) {
$posts[] = $post;
}
}
include VIEWS_PATH . 'homepage/category_box.php';
}
這是該類別盒一個視圖文件:
<div class="category-box">
<div class="category-name">
<?php print $category_name ?>
</div><!-- end div.category-name -->
<div class="category-box-content">
<h2><a href="#"><?php print $post['post_title']; ?></a></h2>
<div class="published-date">
<?php print $post['post_published_date']; ?>
</div><!-- end div.published-date -->
<div class="main-photo">
<a href="#"><img src="<?php print BASE_URL . 'public/uploads/images/' . $post['post_photo']; ?>" alt=""></a>
<span class="photo-caption">
<?php print $post['post_photo_caption']; ?>
</span><!-- end div.photo-caption -->
</div><!-- end div.main-photo -->
<div class="excerpt">
<a href="#"
title="<?php print $post['post_content']; ?>"><?php print $post['post_content']; ?></a>
</div><!-- end div.excerpt -->
<div class="latest-posts">
<div class="more-publications">
More publications in <?php print $category_name ?>
</div>
<ul>
<?php
foreach ($this->current_category_posts as $post_in_list) {
if ($post_in_list['category_id'] === $category_id) {
print '<li><a href="#" title="' . $post_in_list['post_title'] . '" >' .
$post_in_list['post_title'];
'</a></li>';
}
}
?>
</ul>
<a href="#" class="all-publications">All publications »</a>
<div class="clearfix"></div>
</div><!-- end div.latest-posts -->
</div><!-- end div.category-box-content -->
</div><!-- end div.category-box -->
我這是怎麼顯示每箱(也許不是這個問題很重要):
$post->category_box("1", "World");
$post->category_box("2", "Politics");
$post->category_box("3", "Culture");
$post->category_box("4", "Technologies");
$post->category_box("5", "Sports");
$post->category_box("6", "Art");
我該如何做到這一點?
非常感謝!
很難說出你的實際問題在這裏(以及它與第一個不同)。在第一個帖子顯示爲「僅鏈接」之後,剩下的帖子是否會顯示,因此不是_full_張貼視圖,主要問題?那麼你可以簡單地爲方法'category_box'添加第三個參數,將其命名爲'$ show_full_view'或者其他內容 - 然後在第一次調用時傳遞'true',而對於以下所有內容傳遞'false'。並且,在該方法中,您根據該值決定要顯示的內容。 – CBroe
嗯!有趣。聽起來很難,但我會嘗試!謝謝你的想法。 :) –
哦..參數在帖子的整個框中...嗯.. –