Jump to content

How to Limit Foreach Results to Just the First Item - and ignore the rest?


Recommended Posts

Hi, I'm coding a pile of research that ends up being tagged for a variety of issue areas: early childhood, human rights, justice, etc. Using a multiple page array field to make it easy to select an unlimited number of issues.

In most cases I want to spit out that whole list when the research blocks come up with titles, links, images, etc. so people can click any issue area listed... like this...

foreach($feature->issue as $item) {
 echo "<li class='iss uk-text-tiny bold caps'><a href='$item->url'>$item->title</a></li>";

But for the home page, I'd like to restrict the listing of issues to just the first one in the list, as that will be the primary issue area... rather than create a separate field.  The total count doesn't matter because I want to use just the first and ignore the rest...


foreach($feature->issue as $item) {

[select the first issue in the list of supplied issues and then spit that one out linked]

 echo "<p class='iss uk-text-tiny bold caps'><a href='$item->url'>$item->title</a></p>";

I'm getting better and bringing back everything but don't know if I should try to  put in a counter? Establish a limit? ... appreciate any help. 








Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...