Jump to content

Recommended Posts

Posted

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. 

Posted

In Win / Chrome it looks exactly like your screenshot. Styling and inf. scroll seem to work just fine. What are you testing with, and how does it look like on your end?

  • Like 1
Posted

@dragan, @wbmnfktr Sorry, it's not the site I'm working on, its just an example what I need. ☺️

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

Posted
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
Posted

@BitPoet's groupBy() hook is nice for this sort of thing. As with @teppo's suggestion, you'd have to do a bit more to get it working with infinite scroll (the limit might fall in the middle of a day, in which case you wouldn't want the day heading added again on the next pagination).

2019-06-24_100137.png.279bc3c03f11b550df3c86cbeadeb7d5.png

  • Like 6

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
  • Recently Browsing   0 members

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