Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Created September 29, 2017 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/43f8a9b1d0ab03087e160632ffab8b22 to your computer and use it in GitHub Desktop.
Save steveosoule/43f8a9b1d0ab03087e160632ffab8b22 to your computer and use it in GitHub Desktop.
Miva - Recent WordPress Posts
<mvt:comment>
| ---------------------------------------------
| Display 3 Recent Posts from WordPress
| ---------------------------------------------
</mvt:comment>
<mvt:comment>
| Check for existing data Transient
</mvt:comment>
<mvt:do file="g.Module_Root $ '/modules/util/transients.mvc'" name="l.settings:recent_posts:serialized_data" value="Get_Transient( 'recent_posts' )" />
<mvt:if expr="ISNULL l.settings:recent_posts:serialized_data OR g.update_recent_posts">
<mvt:comment>
| MVT:CALL to WordPress's JSON API Plugin to get 3 recent posts
</mvt:comment>
<mvt:call action="'https://' $ g.domain:name $ '/blog/api/get_recent_posts/?count=3'" method="'GET'" timeout="'1'">
<mvt:assign name="l.settings:recent_posts:json" value="l.settings:recent_posts:json $ s.callvalue" />
</mvt:call>
<mvt:comment>
| Parse, Serialize, and Store the result
</mvt:comment>
<mvt:assign name="l.result" value="miva_json_decode( l.settings:recent_posts:json, l.settings:recent_posts:data )" />
<mvt:assign name="l.settings:recent_posts:serialized_data" value="miva_array_serialize( l.settings:recent_posts:data )" />
<mvt:do file="g.Module_Root $ '/modules/util/transients.mvc'" name="l.result" value="Set_Transient( 'recent_posts', l.settings:recent_posts:serialized_data, 60*60*24)" />
</mvt:if>
<mvt:comment>
| Now `l.settings:recent_posts:data` has the data we need
</mvt:comment>
<mvt:assign name="l.settings:recent_posts:data" value="miva_array_deserialize( l.settings:recent_posts:serialized_data )" />
<h5 class="footer__heading"><a href="/blog/">Latest from the Blog</a></h5>
<mvt:foreach array="recent_posts:data:posts" iterator="post">
<div class="row footer-media">
<div class="column one-fourth">
<a href="&mvt:post:url;">
<mvt:if expr="l.settings:post:thumbnail">
<mvt:assign name="l.settings:post:thumbnail" value="glosub( l.settings:post:thumbnail, 'http://', '//' )" />
<img class="lazy-load" data-src="&mvt:post:thumbnail;" alt="&mvt:post:title;">
<mvt:else>
<img class="lazy-load" data-src="graphics/00000001/placeholder-image_80x80.jpg" alt="&mvt:post:title;">
</mvt:if>
</a>
</div>
<div class="column three-fourths">
<a href="&mvt:post:url;" class="footer-media__heading">&mvt:post:title;</a>
<div class="footer-media__summary">
&mvt:post:excerpt;
<a href="&mvt:post:url;" class="footer-media__more">Read More</a>
</div>
</div>
</div>
</mvt:foreach>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment