Created
February 12, 2017 04:46
-
-
Save mwordpress/10a916d744a5dc3f91fc056f9d9e87a7 to your computer and use it in GitHub Desktop.
the codes listed here is part of the following article : https://www.mwordpress.net/how-to-create-archive-page-for-wordpress-blog/
This file contains 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 | |
/* | |
Template Name: Full Archive | |
*/ | |
?> | |
<?php | |
/** | |
* The template for displaying pages | |
* | |
* This is the template that displays all pages by default. | |
* Please note that this is the WordPress construct of pages and that | |
* other "pages" on your WordPress site will use a different template. | |
* | |
* @package WordPress | |
* @subpackage Twenty_Sixteen | |
* @since Twenty Sixteen 1.0 | |
*/ | |
get_header(); ?> | |
<div id="primary" class="content-area"> | |
<main id="main" class="site-main" role="main"> | |
<?php | |
// Start the loop. | |
while ( have_posts() ) : the_post(); | |
// Include the page content template. | |
get_template_part( 'template-parts/content', 'page' ); | |
// If comments are open or we have at least one comment, load up the comment template. | |
if ( comments_open() || get_comments_number() ) { | |
comments_template(); | |
} | |
// End of the loop. | |
endwhile; | |
?> | |
</main><!– .site-main –> | |
<?php get_sidebar( 'content-bottom' ); ?> | |
</div><!– .content-area –> | |
<?php get_sidebar(); ?> | |
<?php get_footer(); ?> |
This file contains 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 | |
function full_archive_helper() { | |
$previous_year = $year = 0; | |
$previous_month = $month = 0; | |
$ul_open = false; | |
$myposts = get_posts('numberposts=-1&orderby=post_date&order=DESC'); | |
foreach($myposts as $post) : | |
setup_postdata($post); $year = mysql2date('Y', $post->post_date); | |
$month = mysql2date('n', $post->post_date); | |
$day = mysql2date('j', $post->post_date); | |
if($year != $previous_year || $month != $previous_month) : | |
if($ul_open == true) : | |
echo '</ul>'; | |
endif; | |
echo '<h2>'.get_the_time('F Y', $post->ID).'</h2>'; | |
echo '<ul>'; | |
$ul_open = true; | |
endif; | |
$previous_year = $year; | |
$previous_month = $month; | |
echo '<li class="hentry"> | |
<span>'. get_the_time('j F', $post->ID).'</span> – <a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a> | |
</li>'; | |
endforeach; | |
echo '</ul>'; | |
} | |
function archive_shortcode( $atts, $content = null ) { | |
ob_start(); | |
$output = full_archive_helper(); | |
$output .= ob_get_clean(); | |
return $output; | |
} | |
if (!is_admin()) { | |
add_shortcode("arch", "archive_shortcode"); | |
} | |
?> |
This file contains 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 | |
/* | |
Template Name: Full Archive | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment