mariazelenova Posted February 24, 2014 Share Posted February 24, 2014 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 } } } Quote Link to comment https://forums.phpfreaks.com/topic/286496-display-boxes-with-news-from-every-category/ Share on other sites More sharing options...
.josh Posted February 24, 2014 Share Posted February 24, 2014 so where/how are you setting $_id and $category_id Quote Link to comment https://forums.phpfreaks.com/topic/286496-display-boxes-with-news-from-every-category/#findComment-1470523 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.