【发布时间】:2016-09-10 22:51:39
【问题描述】:
我正在尝试向我的 wordpress 主题添加一些代码,以在帖子底部显示分页。 这是我的分页循环:
<main id="main">
<?php
// the query
$args = array('posts_per_page' => 2 );
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) { ?>
<!-- loop -->
<?php while ( $the_query->have_posts() ) {
$the_query->the_post(); ?>
<article id="post">
<div id="thumbnail">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail(); } ?>
</div>
<h2><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2>
<div class="entry">
<?php the_excerpt(); ?>
</div>
</article>
<?php } } else { ?>
<p><?php _e( 'Die Posts entsprechen nicht den Kriterien.' ); ?></p>
<?php } ?>
<!-- pagination -->
<?php
if($the_query->max_num_pages>1){?>
<p class="paged">
<?php
if ($paged > 1) { ?>
<a href="<?php echo '?paged=' . ($paged -1); //prev link ?>"><</a>
<?php }
for($i=1;$i<=$the_query->max_num_pages;$i++){?>
<a href="<?php echo '?paged=' . $i; ?>" <?php echo ($paged==$i)? 'class="selected"':'';?>><?php echo $i;?></a>
<?php
}
if($paged < $the_query->max_num_pages){?>
<a href="<?php echo '?paged=' . ($paged + 1); //next link ?>">></a>
<?php } ?>
</p>
<?php } ?>
<!-- end pagination -->
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
</main>
当我查看源代码时,我找不到分页。我究竟做错了什么?找不到答案,没有代码适合我。如果有人可以帮助我,那就太好了。 :)
【问题讨论】:
标签: php html wordpress web wordpress-theming