Skip to content

Instantly share code, notes, and snippets.

@tessguefen
Last active May 17, 2018 16:50
Show Gist options
  • Save tessguefen/491a89aa01d45a8998d3a40ba4d85298 to your computer and use it in GitHub Desktop.
Save tessguefen/491a89aa01d45a8998d3a40ba4d85298 to your computer and use it in GitHub Desktop.
Instagram Feed
<mvt:assign name="l.instagram_feed" value="''" />
<mvt:call action="'https://api.instagram.com/v1/users/self/media/recent/?access_token=[ TOKEN HERE ]'" method="'GET'">
<mvt:assign name="l.instagram_feed" value="l.instagram_feed $ s.callvalue" />
</mvt:call>
<mvt:comment> Decode API JSON </mvt:comment>
<mvt:assign name="l.success" value="miva_json_decode( l.instagram_feed, l.settings:instagram )" />
<mvt:if expr="NOT miva_array_elements( l.settings:instagram:data )">
<mvt:exit />
</mvt:if>
<mvt:foreach iterator="post" array="instagram:data">
<a href="&mvte:post:link;" target="_blank">
<img src="&mvte:post:images:standard_resolution:url;" alt="&mvte:post:caption:text;" title="&mvte:post:caption:text;" />
</a>
</mvt:foreach>
<mvt:do file="g.Module_Root $ '/modules/util/transients.mvc'" name="l.instagram_feed" value="Get_Transient( 'instagram_feed' )" />
<mvt:if expr="ISNULL l.instagram_feed">
<mvt:assign name="l.instagram_feed" value="''" />
<mvt:call action="'https://api.instagram.com/v1/users/self/media/recent/?access_token=[ TOKEN HERE ]'" method="'GET'">
<mvt:assign name="l.instagram_feed" value="l.instagram_feed $ s.callvalue" />
</mvt:call>
<mvt:comment> Store in Cache | 1 Hour Expriation Date </mvt:comment>
<mvt:do file="g.Module_Root $ '/modules/util/transients.mvc'" value="Set_Transient( 'instagram_feed', l.instagram_feed, 60 * 60 )" />
</mvt:if>
<mvt:comment> Decode API JSON </mvt:comment>
<mvt:assign name="l.success" value="miva_json_decode( l.instagram_feed, l.settings:instagram )" />
<mvt:if expr="NOT miva_array_elements( l.settings:instagram:data )">
<mvt:exit />
</mvt:if>
<mvt:foreach iterator="post" array="instagram:data">
<a href="&mvte:post:link;" target="_blank">
<img src="&mvte:post:images:standard_resolution:url;" alt="&mvte:post:caption:text;" title="&mvte:post:caption:text;" />
</a>
</mvt:foreach>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment