Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for next or previous image/post? #47

Closed
ballmannweber opened this issue Oct 5, 2021 · 3 comments
Closed

Example for next or previous image/post? #47

ballmannweber opened this issue Oct 5, 2021 · 3 comments

Comments

@ballmannweber
Copy link

hey there!
I bought and installed your nice craftagram and try to get it showing one image/post at a time with two links beneath that let me click to next or the previous image. can you post a small example for that behaviour?

thank you very much in advance!
matthias

@jsmrtn
Copy link
Owner

jsmrtn commented Oct 6, 2021

You would want something like this–I haven't tested this but it should work functionally I believe. You would probably want to check that cursors.before and cursors.after exist, so you can hide the link when it isn't available.

{% set craftagram = craft.craftagram.getInstagramFeed(1) %}

{% if craftagram|length %}
    <div data-js="insta-wrapper">
        {% for item in craftagram.data %}
            <img src={{item.media_url}} />
        {% endfor %}
    </div>

    <a data-link="{{ craftagram.paging.cursors.before }}" data-js="load-prev">Load prev</a>
    <a data-link="{{ craftagram.paging.cursors.after }}" data-js="load-next">Load next</a>
{% endif %}

{% js %}
    $("[data-js=load-more]").click(function(e) {
        e.preventDefault();
        $.get("{{ parseEnv(craft.app.sites.primarySite.baseUrl) }}/actions/craftagram/default/get-next-page?siteId={{ currentSite.id }}&limit=1&url=" + $(this).data('after'), function(res) {
            data = $.parseJSON(res);

            // For each, append the item to our wrapper
            $.each(data["data"], function() {
                $("[data-js='insta-wrapper']").html("<img src="+$(this)[0]["media_url"]+" />");
            });

            // Update the paging.
            $("[data-js=load-next]").data("link", data["paging"]["cursors"]["after"]);
            $("[data-js=load-prev]").data("link", data["paging"]["cursors"]["before"]);
        });
    });
{% endjs %}

@ballmannweber
Copy link
Author

thank you for your fast reply!
it’s not working yet but I will look into this.

another quick question: are there tags for number or likes or comments?
item.likes didn’t do the trick.

@jsmrtn
Copy link
Owner

jsmrtn commented Oct 7, 2021

We return all the data provided by the media endpoint, so if it's not listed there, it's not available.

@jsmrtn jsmrtn closed this as completed Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants