这是我到目前为止的内容:那里的类别和新闻。在主页上,每个类别都有一个方框,其中包含一个主要帖子,一个图片和几个仅包含标题的帖子。我可以为每个类别制作一个视图,但我需要以正确的方式(或以某种方式正确的方式)进行。
在我看来,需要一些非常复杂的foreach
声明,但还没有想到任何事情。请给我一些起点。我会非常感谢任何指示,想法或例子。谢谢!
http://oi59.tinypic.com/2i7sgwl.jpg
进展:我以某种方式实现了它:)
http://oi58.tinypic.com/epopiw.jpg
进展::(
以下是我现在所拥有的:
(我在stackoverflow.com找到了这些Category / Post类和模型)
class Post extends Model {
public $rows_posts;
public $rows_featured_posts;
public $_id;
public function get_posts() {
$this->_db->query("SELECT * from posts");
$this->rows_posts = $this->_db->resultset();
}
public function get_ceatured_posts() {
$this->_db->query("SELECT * from posts WHERE featured = 1 LIMIT 1");
$this->rows_featured_posts = $this->_db->resultset();
}
}
儿童班:
class Featured_Publication extends Post {
public $rows_featured_posts;
public function create_featured_post() {
$this->get_ceatured_posts();
foreach ($this->rows_featured_posts as $row_featured_post) {
include_once VIEWS_PATH . 'homepage/featured_publication.php'; // my view for the featured post content box
}
}
}
我可以轻松地为精选帖子执行此操作,但我不知道如何在不同的框中显示所有类别的内容。
我只能在每个方框的顶部显示类别标题,但不能将帖子放在那里。 我认为下面的内容是错误的,因为它根本不起作用。
班级类别:
class Category extends Model {
public $_rows;
public $_id;
public function build_category() {
$this->_db->query("SELECT * from categories");
$this->_rows = $this->_db->resultset();
}
public function category_items() {
$this->_db->query("SELECT * from posts WHERE category_id = '{$this->_id}'");
$this->_rows = $this->_db->resultset();
}
}
儿童班:
class Category_Boxes extends Category {
public $_rows;
public $rows_posts_in_category;
public $category_id;
public function get_posts_from_category() {
$this->build_category();
$this->_db->query("SELECT * from posts WHERE category_id = '{$this->category_id['category_id']}'");
$this->rows_posts_in_category = $this->_db->resultset();
}
public function build_category_box() {
$this->build_category();
$this->get_posts_from_category();
foreach ($this->_rows as $row) {
include VIEWS_PATH . 'homepage/category_box.php'; // Here is my view for the category box
}
}
}