这里是对Devin Walker的答案的改进。这是专门用于存档的。php,但可以适应其他循环。
它还使用WordPress的本地导航链接,而不是page\\u navi()
希望这对别人有帮助。
<?php
/**
* Archive Page
*
* @Since 1.0
*/
// Exit if accessed directly
if ( !defined(\'ABSPATH\')) exit;
?>
<?php get_header(); ?>
<div class="container">
<div class="row">
<?php
// Note - Set number of posts per page in WP-Admin > Settings > Reading > \'Blog pages show at most\'
$args = array(
\'post_type\' => \'post\',
\'paged\' => get_query_var(\'paged\'),
\'cat\' => get_query_var(\'cat\'),
);
$wp_query = new WP_Query( $args );
while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div class="col-md-4 post-card archive my-4">
<div class="text-center">
<a href="<?php the_permalink(); ?>"><img src="<?php echo the_post_thumbnail_url(\'card-size\'); ?>"></a>
</div>
<div class="post-card-details archive-post-details px-4 pb-2">
<h3 class="post-card-category px-4 py-2"><?php single_cat_title(); ?></h3>
<h3 class="post-card-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p class="post-card-p"><?php echo apply_filters( \'the_content\', wp_trim_words( strip_tags( get_post_field(\'post_content\') ), 15 ) ); ?></p>
</div>
</div>
<?php endwhile; ?>
</div>
<!-- Navigation -->
<div class="tablet-pill tablet-pill-purple mb-5"><?php previous_posts_link( \'Previous Page\' ); ?> <?php if(get_previous_posts_link() && get_next_posts_link()) echo \' - \'; ?> <?php next_posts_link( \'Next Page\' ); ?></div>
<?php wp_reset_query(); ?>
</div>
<?php get_footer();