some follow up, a friend of mine helps me for achieving this, and I post the code here if it can help somebody else.
My first code, works but no random:
<?php
$projects = page('projets')->children()->visible();
$testimonials = new Structure();
$key = 0;
foreach($projects as $p) {
foreach($p->clientTestimonials()->toStructure() as $item) {
$testimonials->append($key, $item);
$key++;
}
}
foreach ($testimonials->limit(5) as $testimonial): ?>
<li class="item">
<div class="testimonial-block">
<blockquote>
<?php echo $testimonial->clientTestimonial()->kt() ?>
</blockquote>
<div class="testimonial-avatar"><img src="http://placehold.it/100x100&text=IMAGE+PLACEHOLDER" alt="" height="60" width="60"></div>
<div class="testimonial-info">
<div class="testimonial-info-in">
<strong><?php echo $testimonial->clientTestimonialName() ?></strong><span><?php echo $testimonial->clientTestimonialRole() ?></span>
</div>
</div>
</div>
</li>
<?php endforeach ?>
the code with “all array” in vanilla PHP + randomisation and limit to 5 items:
<?php
$projects = page('projets')->children()->visible();
$testimonials = array();
foreach($projects as $p) {
foreach($p->clientTestimonials()->yaml() as $item) {
$testimonials[] = $item;
}
}
shuffle($testimonials);
$testimonialscount = count($testimonials);
$i = 0;
while($i < 5) { ?>
<li class="item">
<div class="testimonial-block">
<blockquote>
<?php echo $testimonials[$i]["clientTestimonial"]; ?>
</blockquote>
<div class="testimonial-avatar"><img src="http://placehold.it/100x100&text=IMAGE+PLACEHOLDER" alt="" height="60" width="60"></div>
<div class="testimonial-info">
<div class="testimonial-info-in">
<strong><?php echo $testimonials[$i]["clientTestimonialName"]; ?></strong><span><?php echo $testimonials[$i]["clientTestimonialRole"]; ?></span>
</div>
</div>
</div>
</li>
<?php $i++;
if($i >= $testimonialscount): break; endif;
}
?>
Thanks everybody!