Fatal error: Using $this when not in object context-Collection of common programming errors

I am using smarty templates for pinnaclecart to pull post data from wordpress database so the website can show the blog posts. I fixed IF unexpected error but now it is back to $this. I m stuck 🙁

public_blog.php

EDIT back

    function getPosts()
{
        $query= $this->db->query("
        SELECT * from wp_posts where post_status='publish' AND post_type = 'post'
        ");

        $posts = array();
        if ($this->db->moveNext($query, MYSQL_ASSOC))
        {
                 $posts[] = $this->db->col;

        }
return $posts;

}
$posts = getPosts();
view()->assign("body", "templates/pages/site/blog.html");

Could not figure IF error part

The help will be appreciated.