Skip to content

Instantly share code, notes, and snippets.

@hissy hissy/blog.php
Last active Dec 15, 2015

Embed
What would you like to do?
#WordPress use page template for archive with WP_Query
<?php
/**
* Template Name: Blog Archive
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php
$paged = (int) get_query_var('paged');
$args = array(
'posts_per_page' => 10,
'paged' => $paged,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish'
);
$myquery = new WP_Query($args);
if ( $myquery->have_posts() ) :
?>
<header class="archive-header">
<h1 class="archive-title">ブログアーカイブ</h1>
</header><!-- .archive-header -->
<?php
while ( $myquery->have_posts() ) :
$myquery->the_post();
get_template_part( 'content', get_post_format() );
endwhile;
if ( $myquery->max_num_pages > 1 ) :
?>
<nav class="navigation" role="navigation">
<div class="nav-previous alignleft"><?php echo get_next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ), $myquery->max_num_pages ); ?></div>
<div class="nav-next alignright"><?php echo get_previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
</nav>
<?php
endif;
?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
<?php
// reset post data
wp_reset_postdata();
?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.