我的wordpress主题有点问题。因此, 我刚刚创建了一个类别主题, 并且我的永久链接使用了以下结构:/%year%/%monthnum%/%postname%/。
分页起初没有起作用, 但是现在我终于设法使它运行了。链接
<div class="pagination">
<div class="alignleft"><?php previous_posts_link('« neuere Artikel') ?></div>
<div class="alignright"><?php next_posts_link('ältere Artikel »', '') ?></div>
</div>
正在显示。
主要问题是, 当我单击” next_posts”-链接或previous_posts-链接时, 我会得到一个404。
这是我的代码:
<?
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query->query(array(
'posts_per_page' => 5, 'orderby'=> 'menu_order', 'paged'=>$paged
) );
?>
<?php if (have_posts()) : ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="type-post">
<h2><a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a></h2>
<div class="blog-date">
<a class="admin" href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>"><?php the_author_meta('display_name'); ?></a>
<a href="#" class="date"><?php the_time('j. F, Y'); ?></a>
<a href="<?php comments_link(); ?>" class="comments"><?php comments_number('0 Kommentare', '1 Kommentar', '% Kommentare'); ?></a>
</div><!-- close .blog-date -->
<p><? echo wp_trim_words( get_the_content(), 100 ); ?> </p>
<p class="alignright"><a href="blog-single.php" class="button">Read more</a></p>
<div class="clearfix"></div>
</div>
<?php endwhile; ?>
<!-- END Single Content -->
<div class="pagination">
<div class="alignleft"><?php previous_posts_link('« neuere Artikel') ?></div>
<div class="alignright"><?php next_posts_link('ältere Artikel »', '') ?></div>
</div>
<?php endif; ?>
<div class="clearfix"></div>
<!-- END CONTENT -->
<?php $wp_query = null;
$wp_query = $temp; ?>
但这仍然行不通。有人可以帮我吗?提前致谢。 <3
#1
去
Settings -> Reading
并将”博客”页面设置为最多显示, “联合供稿” Feed显示的最新内容与wp_query-> query中的posts_per_page选项相同。
#2
在你的代码$ paged =(get_query_var(‘paged’))中? get_query_var(‘paged’):1;
get_query_var(‘paged’)替换为get_query_var(‘page’)
#3
<?php
global $wp_query;
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'your post type', //Post type
'posts_per_page' => 5, //How many post u want to display per page
'paged' => $paged , 'orderby'=> 'menu_order', );
$the_query = new WP_Query( $args );
if (have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div class="type-post">
<h2><a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a></h2>
<div class="blog-date">
<a class="admin" href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>"><?php the_author_meta('display_name'); ?></a>
<a href="#" class="date"><?php the_time('j. F, Y'); ?></a>
<a href="<?php comments_link(); ?>" class="comments"><?php comments_number('0 Kommentare', '1 Kommentar', '% Kommentare'); ?></a>
</div><!-- close .blog-date -->
<p><? echo wp_trim_words( get_the_content(), 100 ); ?> </p>
<p class="alignright"><a href="blog-single.php" class="button">Read more</a></p>
<div class="clearfix"></div>
</div>
<?php endwhile; ?>
<!-- END Single Content -->
<?php endif; ?>
<div class="pagination">
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $wp_query->max_num_pages
) );
?>
</div>
来源:
https://www.srcmini02.com/67701.html