Skip to content

Instantly share code, notes, and snippets.

@whatjackhasmade
Created July 21, 2017 11:06
Show Gist options
  • Save whatjackhasmade/092ebf305d50b01c77cdd943384ebc16 to your computer and use it in GitHub Desktop.
Save whatjackhasmade/092ebf305d50b01c77cdd943384ebc16 to your computer and use it in GitHub Desktop.
Use The Loop To Create An “Archive” Page Template The problem. As noted in the previous hack, a common problem on blogs is that it is hard for readers to find content published a while ago. To help my readers finding what they’re looking for, I created a WordPress page template that displays a list of all posts ever published on my blog. You can…
<?php
/*
Template Name: Archives
*/
?>
<?php get_header(); ?>
<h2><?php $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
if (0 < $numposts) $numposts = number_format($numposts); ?>
<h2><?php echo $numposts.' recipes published since October 06, 2008'; ?>
</h2>
<ul id="archive-list">
<?php
$myposts = get_posts('numberposts=-1&');
foreach($myposts as $post) : ?>
<li><?php the_time('m/d/y') ?>: <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment