Jump to content

Infinite scroll with date separator


Zeka
 Share

Recommended Posts

Hi. 

I need to implement an infinite scroll feature for a news site.
There is no problem in the infinite scroll feature, but list of news should be separated with dates, like on screen image

chrome_WWssoYAjSZ.png

The working example you can find here.
Sadly, but I can't figurate out where to start.
Any ideas are much welcome.
Thanks. 

Link to comment
Share on other sites

2 hours ago, Zeka said:

Basicaly speaking I can't figurate how to transform page array to list separeted by days. 

Perhaps I'm missing the point, but this should be the easy part. Maybe something along these lines:

<?php
$current_date = null;
$items = $pages->find('template=news-item, sort=date_field, start=0, limit=20');
if ($items->count()) {
    foreach ($items as $item) {
        $date = date('j.n.', $item->getUnformatted('date_field'));
        if ($date !== $current_date) {
            if ($current_date !== null) echo "</ul>";
            echo "<h3>{$date}</h3><ul>";
            $current_date = $date;
        }
        echo "<li>{$item->title}</li>";
    }
    echo "<ul>";
}

It's a bit crude and probably wouldn't work as-is with your infinite scroll approach, but that's the basic idea anyway ?

  • Like 5
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...