Welcome Guest, Not a member yet? Register   Sign In
News Postal Home Page
#1

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.
   
Reply
#2

(This post was last modified: 06-03-2018, 04:07 AM by InsiteFX.)

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB