带有静态页面的 Wordpress 分页 [英] Wordpress pagination with static pages
问题描述
我是 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 循环之前添加了这样的东西:
<代码>$paged = (get_query_var('paged')) ?get_query_var('paged') : 1;$args=数组('posts_per_page' =>5、'分页' =>$分页);$wp_query = new WP_Query($args);?>
循环后我会有导航链接:
<div class="nav-previous"><?php next_posts_link();?></div><div class="nav-next"><?php previous_posts_link();?></div></div><!-- #nav-below-->之后我会添加 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屋!
查看全文
相关文章
- Wordpress-页面分页;
- 带有分页的存档页面上的 wordpress 粘性帖子;
- php glob页面的分页;
- 多个页面的 Gatsby 分页;
- Wordpress 指向静态 html 页面;
- 使 Wordpress 页面的标题只读;
- wordpress - 不同页面的独特主题;
- 如何检索 Wordpress 页面的兄弟页面列表?;
- 插件中子页面的WordPress URL解析;
- 将 Wordpress 页面的标题设为只读;
- 如何编辑WordPress页面的html代码;
- 清除部分页面的引导样式;
- 限制分页中可见页面的数量;
- 静态页面的 Htaccess 条件 https;
- Rails指定静态页面的布局;
- 向Wordpress帖子页面添加静态内容?;
- 需要有关 wordpress 档案页面的帮助;
- 刷新包含部分页面的paricular div;
- 如何在wordpress的页面代码中创建分页?;
- 搜索分页 wordpress;
- Jekyll不显示静态页面的布局;
- Facebook带有页面的测试帐户;
- 带有子页面的排版导航;
- 每个页面的 wordpress 不同的横幅图像 - 动态;
- 如何拆分页面并揭示下面的内容?;
其他开发最新文章
- 拒绝显示一个框架,因为它将'X-Frame-Options'设置为'sameorigin';
- 什么是&QUOT; AW&QUOT;在部分标志属性是什么意思?;
- 在运行npm install命令时获取'npm WARN弃用'警告;
- cmake无法找到openssl;
- 从Spark的scala中的* .tar.gz压缩文件中读取HDF5文件;
- Twitter :: Error :: Forbidden - 无法验证您的凭据;
- 我什么时候需要一个fb:app_id或者fb:admins?;
- 将.db文件导入R;
- npm通知创建一个lockfile作为package-lock.json。你应该提交这个文件;
- 拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“script-src'self'”;