CodeIgniter Forums
News Postal Home Page - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: News Postal Home Page (/showthread.php?tid=70809)



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 = [];
    
 
   $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.