Recent blog posts block for non-blog pages

edited July 2013 in Modules
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

  • edited 10:04AM
    If you are using 0.93, you will need to do the following:
    $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();
  • edited 10:04AM
    That's brilliant, really simple. I was expecting something more complex that would need a controller to load the module etc.

    Also, thanks for info on CI() function - really useful.
  • edited 10:04AM
    In which page this code need to be pasted
  • edited 10:04AM
    In a view file, layout file (e.g. views/_layouts/) or controller that you are wanting to display the posts.
  • edited 10:04AM
    Nothing happens . Please provide detailed solution
  • edited 10:04AM
    Its not working. Please provide correct solution for how to render a view from blog module to home page
  • edited 10:04AM
    If you just want to render a view file from the blog module you can do use the "module_view" method on the load object as in the following:
    $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(...)
  • edited 10:04AM
    Thanks. It worked fine
  • edited 10:04AM
    Is it possible to upload video files in blog module?
    If it is, how can i add fields?
  • edited 10:04AM
    Not out of the box. You would need to add an additional field to the fuel_blog_posts table to capture that information and modify the blog_posts_model::form_fields method.
  • edited 10:04AM
    ok. thanks. I will try this.
  • edited 10:04AM
    I want to change the css styles of dynamically generating fields in leave your comment in blog module. Is it possible?
  • edited 10:04AM
    Yes. There is a default assets/css/blog.css file you can edit in particular the .comment_form class.
  • edited 10:04AM
    Table is generating dynamically. Is it possible to remove table and customize it.
  • edited 10:04AM
    Yes. There are a couple ways to do it. The current comment form is using Form_builder and the fuel/modules/blog/config/blog.php has a an array of configuration parameters you can pass it.
    $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.
Sign In or Register to comment.