Skip to content

Instantly share code, notes, and snippets.

@jacobwise
Last active August 29, 2015 14:27
Show Gist options
  • Save jacobwise/ec5f35d7205a7d1aa866 to your computer and use it in GitHub Desktop.
Save jacobwise/ec5f35d7205a7d1aa866 to your computer and use it in GitHub Desktop.
Gets the 4 most recent WordPress posts on the forum.
<?php
$url = 'https://luminous-landscape.com/wp-json/posts?filter[posts_per_page]=4';
get_recent_posts( $url );
function get_recent_posts( $url ) {
$json = file_get_contents($url);
echo '<div class="top-scroll-bar">';
echo '<div class="wrap">';
if ( $json !== FALSE ) {
$obj = json_decode($json);
echo '<span class="title">UPDATES <span class="dashicons dashicons-arrow-right-alt"></span></span> ';
echo '<ul>';
foreach ( $obj as $post ) {
$title = $post->title;
$link = $post->link;
$author = $post->author->name;
echo "<li><a href='$link'>$title</a></li>";
}
echo '</ul>';
echo '<span id="prev" class="dashicons dashicons-arrow-left"></span>';
echo '<span id="next" class="dashicons dashicons-arrow-right"></span>';
}
echo '<a href="https://luminous-landscape.com" class="luminous-home-link">Luminous Landscape Home <span class="dashicons dashicons-redo"></span></a>';
echo '</div>';
echo '</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment