Skip to content

Instantly share code, notes, and snippets.

@daveis
Last active December 30, 2015 15:19
Show Gist options
  • Save daveis/7847951 to your computer and use it in GitHub Desktop.
Save daveis/7847951 to your computer and use it in GitHub Desktop.
A modified version of posts.php from my Anchor theme: Manifesto. (https://github.com/daveis/manifesto-anchor-theme) This code will show the latest article - with just the image, heading, description, and read more link - on the homepage, posts page, and category pages.
<?php theme_include('header'); ?>
<div class="content-bg">
<section class="article-posts">
<!-- Check for posts -->
<?php if(has_posts()): ?>
<!-- Show the full version of most recent post ->
<?php posts(); ?>
<article class="article-post">
<!-- Does it have a featured image? Let's show it. -->
<?php if(article_custom_field('featured-image')): ?>
<div class="featured-image" style="background-image: url(<?php echo article_custom_field('featured-image', 'http://s13.postimg.org/w3p4tc5pz/article_img_default.jpg'); ?>);">
<div class="overlay"></div>
<?php if(article_custom_field('featured-image-credit')): ?>
<div class="featured-image__credit"><?php echo article_custom_field('featured-image-credit'); ?></div>
<?php endif; ?>
<header class="post-header">
<div class="container">
<h1><?php echo article_title(); ?></h1>
<div class="article-meta">
<time class="article-meta__time" datetime="<?php echo date(DATE_W3C, article_time()); ?>"> <i class="fa fa-calendar"></i><?php echo relative_time(article_time()); ?></time>
<!-- Maybe use this later?
<span class="article-meta__author"><i class="fa fa-user"></i> by <?php echo article_author('real_name'); ?></span>
-->
<span class="article-meta__category"><i class="fa fa-folder-o"></i> in <a href="<?php echo article_category_url(); ?>"><?php echo article_category(); ?></a></span>
<span class="article-meta__read-time"><i class="fa fa-clock-o"></i> Read Time: <?php echo dg_est_reading_time(); ?></span>
</div>
<?php if (article_description()): ?>
<p class="lead"><?php echo article_description(); ?></p>
<?php endif; ?>
<a class="article-exceprt__readmore" href="<?php echo article_url(); ?>"> Read More &#8594;</a>
</div>
</header>
</div>
<!-- No featured image? Show just a text header -->
<?php else: ?>
<header class="post-header">
<div class="container">
<h1><?php echo article_title(); ?></h1>
<div class="article-meta">
<time class="article-meta__time" datetime="<?php echo date(DATE_W3C, article_time()); ?>"> <i class="fa fa-calendar"></i><?php echo relative_time(article_time()); ?></time>
<!-- Maybe use this later?
<span class="article-meta__author"><i class="fa fa-user"></i> by <?php echo article_author('real_name'); ?></span>
-->
<span class="article-meta__category"><i class="fa fa-folder-o"></i> in <a href="<?php echo article_category_url(); ?>"><?php echo article_category(); ?></a></span>
<span class="article-meta__read-time"><i class="fa fa-clock-o"></i> Read Time: <?php echo dg_est_reading_time(); ?></span>
</div>
<?php if (article_description()): ?>
<p class="lead"><?php echo article_description(); ?></p>
<?php endif; ?>
<a class="article-exceprt__readmore" href="<?php echo article_url(); ?>"> Read More &#8594;</a>
</div>
</header>
<?php endif; ?>
</article>
<!-- A little line break between article and posts list -->
<hr>
<!-- look for the other posts, but only display titles and descriptions -->
<?php while(posts()): ?>
<article class="article-excerpt">
<div class="container">
<h2 class="article-excerpt__headline"><a class="dark" href="<?php echo article_url(); ?>"><?php echo article_title(); ?></a></h2>
<div class="article-meta">
<time class="article-meta__time" datetime="<?php echo date(DATE_W3C, article_time()); ?>"> <i class="fa fa-calendar"></i><?php echo relative_time(article_time()); ?></time>
<!-- Maybe use this later?
<span class="article-meta__author"><i class="fa fa-user"></i> by <?php echo article_author('real_name'); ?></span>
-->
<span class="article-meta__category"><i class="fa fa-folder-o"></i> in <a href="<?php echo article_category_url(); ?>"><?php echo article_category(); ?></a></span>
<span class="article-meta__read-time"><i class="fa fa-clock-o"></i> Read Time: <?php echo dg_est_reading_time(); ?></span>
</div>
<?php if (article_description()): ?>
<div class="article-excerpt__intro">
<p><?php echo article_description(); ?><a class="article-exceprt__readmore" href="<?php echo article_url(); ?>"> Continue Reading &#8594;</a></p>
</div>
<?php endif; ?>
</div>
</article>
<?php endwhile; ?>
<?php if(has_pagination()): ?>
<nav class="pagination container clearfix">
<?php echo posts_prev('<i class="fa fa-chevron-circle-left"></i><span> older posts</span>', '<a><i class="fa fa-chevron-circle-left"></i><span> older posts</span></a>'); ?><?php echo posts_next('<span>newer posts </span><i class="fa fa-chevron-circle-right"></i>', '<a><span>newer posts </span><i class="fa fa-chevron-circle-right"></i></a>'); ?>
</nav>
<?php endif; ?>
<?php else: ?>
<div class="container">
<p>Yeah, I haven't actually written anything yet.</p>
</div>
<?php endif; ?>
</section>
</div>
<?php theme_include('footer'); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment