MaryMatlow Posted May 10, 2017 Share Posted May 10, 2017 I want to revive this thread as I could not find the solution I'm looking for. I've a function using the "repeater" field. I'm using it to display portfolio items (images and text). What I want to achieve is render the items according to category, such as, Web, Print, In Progress etc. I've created a field within "repeater" to specify the category. I've no idea how to make it work. This is the function I'm using: function bsRenderPortfolio($portfolio) { $out = "<div class='row portfolio'>"; foreach ($portfolio as $item) { $imgname=""; foreach($item->images as $img){ $imgname="<img class='portfolio-image img-responsive' src='".$img->url."' />"; } $out .= "<div class='portfolio-item'> <div class='col-xs-12 col-sm-6'> <figure class='wow fadeInLeft animated' data-wow-duration='500ms' data-wow-delay='300ms'> <div class='img-wrapper'> {$imgname} <div class='overlay'> <div class='summary'> <p>{$item->summary}</p> </div> <div class='buttons'> <p><a class='btn btn-lg' href='{$item->button_link}' role='button' data-toggle='tooltip' data-placement='right' title='{$item->button_tooltip}'> {$item->button_title}</a></p> </div> </div> <figcaption> <h3> $item->title} </h3> <h5> {$item->subheading} </h5> </figcaption> </div> </figure> </div> </div>"; } $out .= "</div>"; return $out; } And this is how it is being rendered: if($page->portfolio) $content .= bsRenderPortfolio($page->portfolio); Any help would be greatly appreciated. Thanks. Link to comment Share on other sites More sharing options...
Robin S Posted May 11, 2017 Share Posted May 11, 2017 @MaryMatlow, see the sort() method. function bsRenderPortfolio($portfolio) { $portfolio->sort('my_field_name'); // insert the name of the category field you want to sort by // ... } 2 Link to comment Share on other sites More sharing options...
MaryMatlow Posted May 12, 2017 Share Posted May 12, 2017 Thanks a ton @Robin S. It worked. Although I had to add some code to create a heading for each category. Thanks once again. Cheers!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now