Display boxes with news from every category

I am learning so please excuse my lame questions!

Here is what I have so far: Categories, of course and news in there. On the home page I have a box for every category with one main post, a picture and several more posts with titles only. I can make a view for every category with my basic skills but I need to do it the right way (or somehow the right way).

It seems to me like some very complicated foreach statement but nothing has come to mind yet. Give me some starting point please. I would be very grateful for any directions, ideas or examples. Thank you!

Featured post:

Progress: I made it happen somehow :slight_smile:
Categories boxes:

Progress: :frowning:

Here is what I have for now:

[php]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();
}

}[/php]

Child Class:

[php]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
    }
}

}[/php]

I can do this for Featured posts, but I don’t know how to show the contents from all categories in different boxes.

I can only show the category title on the top of each box, but cannot put the posts in there. I suppose this below is wrong because it is not working at all.

A class Category:

[php]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();
}

}[/php]

Child Class:

[php]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
    }
}

}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service