Searching by tags with limit and offset
I have a News module which uses Fuel's Tags module. I am trying to retrieve a limited amount of record with an offset from the News module of a certain tag for pagination. I also would like it to be ordered by date in a descending order. I've tried searching by tags using fuel_model first but I failed to realize that the WHERE clause is for searching tags. It would be great help if anyone could provide a solution.
Comments
$slug = uri_segment(3); // or whatever URI segment the tag slug is $tag = $CI->fuel->tags->find_by_tag($slug); $news_model = $tag->get_news(TRUE); $limit = 10; $offset = 10; $items = $news_model->find_all(array(), 'publish_date desc', $limit, $offset);
Note the $news_model = $tag->get_news(TRUE);. The "get_news" method maps to essentially $tag->news. However, passing TRUE to it will return a reference to the news model with the "where_in" active record already applied to it so you can do further manipulation such as setting the ordering, offset and limit.
Also, FUEL has some built in capabilities to generate those module tag pages for you.
http://docs.getfuelcms.com/modules/simple#post_pages
We have a demo site that you can download from GitHub that helps demonstrate this and includes both a news and an events type module:
https://github.com/daylightstudio/daylight-roasters
Call to a member function get_news() on a non-object