Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Latest Posts V2

Started by Muut Archive 11 years ago · 3 replies · 327 views
11 years ago

I am back with this question :( The plugin creation was just abit to much for me so cant use that option... I have seen in the learn section a blog version which after changing a few variables is working for me :D

Now I am attempting to use this on another part of the site but the url structure is more complex so am struggling a bit.

Basically I have this working for :-

TXT
Wallpapers
    -Wallpaper 1
    -Wallpaper 2
    -ETC

So everything from 2nd level works...

TXT
Discography
    -A
        -Ary
              Album 1
              Album 2
        -Aman
              Album 1
              Album 2
    -B 
        -B21
              Album 1
              Album 2
        -Babbu
              Album 1
              Album 2

URL: /discography/a/ary/album-1/

So what I am looking to do is get back the last modified Albums (Only)... Twig is as below:-

HTML
                    <div class="def-block widget">
                        <h4> Latest Discography Albums </h4><span class="liner"></span>
                        <div class="widget-content row-fluid">
                            <div class="videos clearfix flexslider">
                                <ul class="slides">
                                    {% for p in page.find('/discography').children.order('date', 'desc').slice(0, 8) %}
                                    <li class="featured-video">
                                        <a href="{{ p.url }}">
                                            {{ pages.find('/images/discography-artists/250x250').media.images[p.header.image~'.jpg'] }}
                                            <h3>{{ p.header.title }}</h3>
                                            <span>{{ p.header.album }}</span>
                                        </a>
                                    </li><!-- slide -->
                                    {% endfor %}
                                </ul>
                            </div>
                        </div><!-- widget content -->
                    </div><!-- def block widget videos -->

I cant seem to figure out the .children bit as unsure how to force it to look down 2 levels of folders for changes... Currently it goes down to the A/B/C folders and just outputs the last modified dates of these but I need it to go down to artist name and then album-name and list the last modified albums.

11 years ago

You will need to do multiple for loops, possibly with recursion. To go over all the current children, then if a child has children of it's own, go over those.

You can see an example of this using a twig macro in the Antimatter theme's templates/partials/navigation.html.twig file.

11 years ago

Hmmm, also seems over complicated for me :(

Guess I will need to keep manually updating the homepage with areas that have multiple folders.

11 years ago

It's really not that complicated, like I said, the navigation in Antimatter is kind of doing something similar, so it makes sense to just read the code.

If you want to do something custom, you have to expect to have to write something custom to make it happen. Grav is about keeping things simple, that sometimes means, making it easy to create some custom functionality, but you still need to create it.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1334 9 years ago
Archive · by Muut Archive, 9 years ago
2 924 9 years ago
Archive · by Muut Archive, 9 years ago
2 4055 9 years ago
Archive · by Muut Archive, 9 years ago
1 2938 9 years ago
Archive · by Muut Archive, 9 years ago
3 1111 9 years ago