Skip to content

Instantly share code, notes, and snippets.

@tannerm
Last active November 27, 2023 17:52
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 tannerm/b45a2cd9753446c99ed8a33d028174c7 to your computer and use it in GitHub Desktop.
Save tannerm/b45a2cd9753446c99ed8a33d028174c7 to your computer and use it in GitHub Desktop.
<?php
// Edited by Mission Lab on 7/31/2023 to add SubStack posts
$api_url = 'https://substackapi.com/api/feeds/[your-username].substack.com?sort=new&limit=4';
// Set up cURL to fetch data from the Substack API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Fetch the data
$response = curl_exec($ch);
curl_close($ch);
// Return the response
$features = json_decode( $response );
// get the first item as the main featured post
$main_feature = array_shift( $features );
?>
<div class="featured_articles">
<div class="row align-center">
<div class="columns large-11 centered">
<div class="row main-feature pb-2 show-for-large">
<div class="columns large-7 medium-6 small-12 bg-white">
<a href="<?php echo esc_url( $main_feature->canonical_url ); ?>">
<div class="content">
<h3><?php echo esc_html( $main_feature->title ); ?></h3>
<p><?php echo wp_trim_words($main_feature->truncated_body_text, 25, '...') ?></p>
<a class="link" href="<?php echo esc_url( $main_feature->canonical_url ); ?>">Read More</a>
</div>
</a>
</div>
<div class="columns large-5 medium-6 small-12 img-holder" style="background: url('<?php echo esc_url( $main_feature->cover_image ); ?>') no-repeat top center / cover;"></div>
</div>
<div class="row features">
<div class="columns large-4 medium-6 small-12 hide-for-large">
<a href="<?php echo esc_url( $main_feature->canonical_url ); ?>">
<div class="img-holder" style="background: url('<?php echo esc_url( $main_feature->cover_image ); ?>') no-repeat top center / cover;"></div>
<div class="content bg-white">
<h3><?php echo esc_html( $main_feature->title ); ?></h3>
<p><?php echo wp_trim_words($main_feature->truncated_body_text, 25, '...') ?></p>
<a class="link" href="<?php echo esc_url( $main_feature->canonical_url ); ?>">Read More</a>
</div>
</a>
</div>
<?php foreach($features as $feature): ?>
<div class="columns large-4 medium-6 small-12">
<a href="<?php echo esc_url( $feature->canonical_url ); ?>">
<div class="img-holder" style="background: url('<?php echo esc_url( $feature->cover_image ); ?>') no-repeat top center / cover;"></div>
<div class="content bg-white">
<h5><?php echo esc_html( $feature->title ); ?></h5>
<p><?php echo wp_trim_words($feature->truncated_body_text, 25, '...') ?></p>
<a class="link" href="<?php echo esc_url( $feature->canonical_url ); ?>">Read More</a>
</div>
</a>
</div>
<?php endforeach; ?>
</div>
<div class="row pt-3">
<div class="columns small-12 text-center">
<h3 class="pb-1">VIEW ALL POSTS</h3>
<a href="https://[your-username].substack.com" class="button outline">Read Now</a>
</div>
</div>
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment