Jump to content

Display boxes with news from every category


mariazelenova

Recommended Posts

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:http://oi59.tinypic.com/2i7sgwl.jpg

 

Progress: I made it happen somehow :)

Categories boxes:

http://oi58.tinypic.com/epopiw.jpg

 

Progress: :(

 

Here is what I have for now:

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

}

Child Class:

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';
        }
    }

}

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:

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

}

Child Class:

 


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
        }
    }

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.