Last active
April 9, 2017 17:26
-
-
Save nickwynja/5760252 to your computer and use it in GitHub Desktop.
Adding an archive page to Second Crack / Continental
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /// Add this function to Post.php | |
| public function write_archive($posts) | |
| { | |
| $template = Updater::$archive_page_template; | |
| $t = new Template($template); | |
| $t->content = array( | |
| 'post-title' => 'Archive', | |
| 'post-type' => 'archive', | |
| 'page-type' => 'page', | |
| 'page-title' => 'Archive', | |
| 'blog-title' => html_entity_decode(SmartyPants(self::$blog_title), ENT_QUOTES, 'UTF-8') | |
| ); | |
| foreach ($posts as $post) { | |
| $t->content['posts'][] = array( | |
| 'title' => html_entity_decode(SmartyPants($post->title), ENT_QUOTES, 'UTF-8'), | |
| 'timestamp' => $post->timestamp, | |
| 'uri' => '/'.$post->year.'/'.str_pad($post->month, 2, '0', STR_PAD_LEFT).'/'.$post->slug, | |
| 'tags' => $post->tags, | |
| ); | |
| $output_html = $t->outputHTML(); | |
| } | |
| if (! file_exists(Updater::$dest_path)) mkdir_as_parent_owner(Updater::$dest_path, 0755, true); | |
| file_put_contents_as_dir_owner(Updater::$dest_path . '/archive.html', $output_html); | |
| } | |
| /// In Updater.php, define your template | |
| public static $archive_page_template = 'archive.php'; | |
| /// Right above "Updating RSS" in Updater.php (line 576 if you're running stock Second Crack) | |
| error_log("Updating Archive..."); | |
| $archive_page_array = Post::from_files(self::most_recent_post_filenames(0)); | |
| Post::write_archive($archive_page_array); | |
| /// In your `archive.php` template, include a loop such as this: | |
| <?php foreach ($content as $post): ?> | |
| <div class='archive'> | |
| <a href='<?php echo $post['uri']; ?>'> | |
| <?php echo $post['title'];?> | |
| </a> | |
| <span class='archive-date'> | |
| <?php echo date('M d, Y', $post['timestamp']); ?> | |
| </span> | |
| </div> | |
| <?php endforeach ;?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment