Recent blog posts block for non-blog pages
I'm trying to figure out how to show the last few blog posts on my homepage. I created a block and called....
$this->fuel_blog->get_recent_posts(2)
But that gives me the error Undefined property: MY_Loader::$fuel_blog
I understand from my prior experience with codeignighter that I need to load that library - is this possible for a CMS page?
If I create a controller can I still have the content loaded from the CMS? And what do I do to load the blog..
$this->load->library('blog'); ??
That would be standard CI for loading a library but I realise the blog is a module not a library.
Thanks for any help you can give, am loving Fuel so far BTW !
Comments
$CI =& get_instance(); $CI->load->library('fuel_blog'); $posts = $CI->fuel_blog->get_recent_posts(2);
For 1.0, you can just call the following:
$CI = & get_instance(); $posts = $CI->fuel->blog->recent_items(2);
Or even shorter in 1.0:
$posts = CI()->fuel->blog->recent_items(2)
The "CI()" function is a shortcut for $CI =& get_instance();
Also, thanks for info on CI() function - really useful.
$this->load->module_view(BLOG_FOLDER, 'my_blog_view', $vars);
$this is a reference to the global CI object (so also could be written as CI()->load->module_view(...)
If it is, how can i add fields?
$config['blog']['comment_form'] = array();
http://docs.getfuelcms.com/libraries/form_builder
However, it sounds like you may want to completely customize the form which you can do as well. There is a fuel/modules/blog/views/themes/default/_blocks/comment_form.php file that you can customize to include whatever form HTML you want. It currently is using the $form variable. If you've created a different theme, then the file will need to change in your respective theme.