CodeIgniter Forums
News Postal Home Page - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: News Postal Home Page (/thread-70809.html)

News Postal Home Page - rmcdahal - 06-02-2018

I am currently working on a news portal using CI3,
backend is ready and no ideas with home page,how can i get posts in home page from certain category,and display as blocks as in screenshots.Help will appreciate,since this is my first projects on codeigniter.

RE: News Postal Home Page - InsiteFX - 06-03-2018

This is one way of doing it, depends on how your database and tables are setup.

PHP Code:
public function getAllPostsByCategory($categoryId)
   $data = [];
   $query $this->db->get('posts');
   if ($query->num_rows() > 0)
       foreach ($query->result_array() as $row)
           $data[] = $row;

   return $data;

You need to have a category_id in your posts table for this to work.