CodeIgniter Forums

Full Version: News Postal Home Page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
[attachment=1233]
This is one way of doing it, depends on how your database and tables are setup.

PHP Code:
public function getAllPostsByCategory($categoryId)
{
 
   $data = [];
    
 
   $this->db->where("category_id"$categoryId);
 
   $this->db->where('status''published');
    
 
   $query $this->db->get('posts');
    
 
   if ($query->num_rows() > 0)
 
   {
 
       foreach ($query->result_array() as $row)
 
       {
 
           $data[] = $row;
 
       }
 
   }
    
 
   $query->free_result();

 
   return $data;


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