Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Reverse PHP Increment

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #41828
    chrisburton
    Participant

    I’m trying to display a number next to each article with the following code in Kirby.

    $count = 0;
    foreach($page->children()->visible()->flip() as $article):
    $count++
    ?>

    However, it’s outputting like this

    `1 Latest Article`

    `2 Older Article`

    I need it to output like this

    `2 Latest Article `

    `1 Older Article`

    #120192
    hotpink
    Member

    Maybe set the counter to the highest number, and count down.

    I took a peek at the Kirby API cheat sheet I came up with this.

    $count = $page->count();
    foreach($page->children()->visible()->flip() as $article):
    $count–;
    ?>

    http://getkirby.com/content/02-docs/kirby-cheatsheet.pdf

    #120194
    chrisburton
    Participant

    @hotpink I had to change your code as it was counting all the pages, I think (it started from 16).

    $count = $page->children()->count();

    This echos out 0 for the first article where I need it to echo out 1.

    #120196
    chrisburton
    Participant

    Nice @benwalker. Thank you!

    Edit: Also, thank you @hotpink

    #120198
    chrisburton
    Participant

    @BenWalker Your code works perfectly.

    #120227
    c3p0h
    Member

    down

    #120228
    c3p0h
    Member

    wow, code parser is terrible on this site. nvm my help
    http://pastebin.com/h7aCGq0d

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Back End’ is closed to new topics and replies.