带有静态页面的 Wordpress 分页 [英] Wordpress pagination with static pages

查看:26
本文介绍了带有静态页面的 Wordpress 分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 wordpress 的新手.我正在使用我的博客类别将所有帖子显示为静态页面.除了分页外,一切都很好.当我用谷歌搜索时,我发现这是 wordpress 中的一个已知错误.这是我的 page.php 代码:

 

<div id="content" role="main"><?php while ( have_posts() ) : the_post();?><?php get_template_part('内容', '页面');?><?php comments_template( '', true );?><?php endwhile;//循环结束.?></div><!-- #content --></div><!-- #primary -->

我使用 list_category_post 插件进行分页,但它不适用于静态页面.请帮帮我?

解决方案

当我想在静态页面上显示帖子时,我自己生成查询.

我在 while 循环之前添加了这样的东西:

<代码>5、'分页' =>$分页);$wp_query = new WP_Query($args);?>

循环后我会有导航链接:

之后我会添加 wp_reset_query() 来重置原始查询,以防万一其他代码需要它.

I am new to wordpress. I am using my blog category to show all the posts as static pages. Every thing is fine except the pagination. When i googled i found that it's a known bug in wordpress.Here is my page.php code:

    <div id="primary">

        <div id="content" role="main">



            <?php while ( have_posts() ) : the_post(); ?>



                <?php get_template_part( 'content', 'page' ); ?>



                <?php comments_template( '', true ); ?>



            <?php endwhile; // end of the loop. ?>


        </div><!-- #content -->

    </div><!-- #primary -->

I am using list_category_post plugin for pagination but it not working with static pages. Please help me ?

解决方案

When I want to show posts on the static page, I generate the query myself.

I add something like this before while loop:

<?
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array(
   'posts_per_page' => 5,
   'paged' => $paged 
 );

$wp_query = new WP_Query($args);
?>

after the loop I would have navigation links:

<div id="nav-below" class="navigation">
  <div class="nav-previous"><?php next_posts_link(); ?></div>
  <div class="nav-next"><?php previous_posts_link(); ?></div>
</div><!-- #nav-below -->

and after that I would add wp_reset_query() to reset the original query, just in case some other code needs it.

<?php wp_reset_query(); ?>

这篇关于带有静态页面的 Wordpress 分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆