Welcome Guest, Not a member yet? Register   Sign In
Adding a category list to the end of each blog post
#6

[eluser]Twisted1919[/eluser]
Code:
function posts()
{
   $posts = $post_categories = array();  
   if($posts = $this->model->get_posts(10))
   {
      foreach($posts AS $post)
      {
         $post_categories[$post->post_id] = $this->model->get_post_categories($post->post_id);
      }
   }
   print_r($posts);
   print_r($post_categories);
}
this should get you an idea on what's in your array .
Also, your method should be like :
Code:
function getPostCategories($post_id)
    {
        $suffix = '_' . $this->lang->lang();
        
        $this->db->select("categories.category{$suffix} as category");
        $this->db->select("categories.id");
        $this->db->join('blog_categories_join', 'blog_categories_join.category_id = categories.id');
        $this->db->where('blog_categories_join.blog_id', $post_id);
        $query= $this->db->get('categories');
        return $query->num_rows() > 0 ? $query->result() : FALSE ;
    }
and finally:
Code:
<?php
    if(!empty($post_categories[$post->id]))
    {
        foreach($post_categories[$post->id] as $category)
        {
            print_r($category->category);
        }
    }
?>
is wrong somehow, don't print_r($category->category) but print_r($category);


Messages In This Thread
Adding a category list to the end of each blog post - by El Forum - 12-04-2010, 08:28 PM
Adding a category list to the end of each blog post - by El Forum - 12-05-2010, 07:26 AM
Adding a category list to the end of each blog post - by El Forum - 12-05-2010, 09:22 AM
Adding a category list to the end of each blog post - by El Forum - 12-05-2010, 06:40 PM
Adding a category list to the end of each blog post - by El Forum - 12-08-2010, 03:13 PM
Adding a category list to the end of each blog post - by El Forum - 12-09-2010, 04:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB