Panel field number sets how many articles on page

I’m setting how many news articles should be rendered on the homepage.

<?php foreach (page('news')->children()->sortBy('date', 'desc')->limit(3) as $article): ?>

So, I need a little help here, how do i insert the number into the limit() within the foreach loop?
Like this somehow?

<?php foreach (page('news')->children()->sortBy('date', 'desc')->limit($articleNum) as $article): ?>

I’m such a noob.

Depends what your field is called:


<?php
$articleNum = $page->articlenum()->value(); // define your variable here fetching the number from the page field
foreach (page('news')->children()->sortBy('date', 'desc')->limit($articleNum) as $article): ?>
1 Like

Oh, that was just as easy as I’d thought. Thanks for clarifying!