Neo Posted June 14, 2015 Share Posted June 14, 2015 I have the following simple site-structure: HOME - Portfolio (portfolio-list.php) - Category A (portfolio-category.php) - item a1 (portfolio-item.php) - item a2 - item a3 - Category B - item b1 - item b2 - item b3 - Category C - item c1 - item c2 - item c3 I would like to show 6 random items from the Portfolio on HOME, for which I wrote the following code: <!-- jCarousel --> <section class="jcarousel recent-work-jc"> <ul> <?php // $portfolio_children = $pages->get("/portfolio/")->children(); // Get children of portfolio page foreach ($portfolio_children as $children) { // Get children's children foreach ($children->children("limit=6, sort=random") as $child) { echo '<li class="four columns">'; echo '<a href="'.$child->url.'" class="portfolio-item">'; echo '<figure>'; $first_image = $child->project_gallery->first()->width(460); echo '<img src="'.$first_image->url.'" alt="'.$first_image->description.'"/>'; echo '<figcaption class="item-description">'; echo '<h5>'.$child->title.'</h5>'; echo '<span>'.$child->parent->title.'</span>'; echo '</figcaption>'; echo '</figure>'; echo '</a>'; echo '</li>'; } } ?> </ul> </section> <!-- jCarousel / End --> The problem is that it gets all portfolio items. The random sorting works, but not the 'limit=6'. Any idea what is wrong? Link to comment Share on other sites More sharing options...
diogo Posted June 14, 2015 Share Posted June 14, 2015 The problem is that you are choosing 6 from each category, and not 6 from all. The ideal would be to get all the portfolio pages with one selector. There are several ways of doing this, the one that looks more logical in your case is to select by template: $portfolio_pages = $pages->find("template=portfolio-item, limit=6, sort=random"); foreach($portfolio_pages as $item) { // echo here } 3 Link to comment Share on other sites More sharing options...
Neo Posted June 15, 2015 Author Share Posted June 15, 2015 Thanks, diogo. That worked and looks much cleaner. 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