为 WordPress 中的不同页面设置不同的分页 [英] Setting different paginations for different pages in WordPress

查看:28
本文介绍了为 WordPress 中的不同页面设置不同的分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 WordPress 驱动网站上有两个页面.

I have two pages on my WordPress driven website.

第一页仅显示一个类别的博客文章例如:类别名称 = 测试

1st page displays blog posts only a single category For example: Category Name = Test

第二页显示所有其他博客帖子

2nd page displays all other blog posts

我要归档的内容:

我希望第一页上每页只显示 5 个帖子.

I want only 5 posts per page to be displayed on the 1st page.

我希望每页仅 15 个帖子显示在第二页上.

I want only 15 posts per page to be displayed on the 2nd page.

谁能告诉我如何存档?

这是仅显示测试类别的博客文章的代码规范

Here is the codespec for displaying blog posts only a Test category

<?php if ( have_posts() ) : ?>
            <?php $paged = get_query_var('paged') ? get_query_var('paged') : 1; query_posts('cat=3&paged='.$paged.'&post_per_page=1'.get_option('posts_per_page')); ?> 
            <?php while ( have_posts() ) : the_post(); ?>
                <?php get_template_part( 'content-test', get_post_format() ); ?>
            <?php endwhile; ?>
            <?php wp_pagination(); ?>  
        <?php else : ?>
        <?php endif; ?>

任何帮助将不胜感激.

推荐答案

经过长时间的研究,这里是我得到的解决方案

After a long of research here is the solution I achived

<?php query_posts( array('posts_per_page' => 2,'cat' => '3','paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),));?>

在'posts_per_page'中设置分页数=> 2,

Set the pagination number in 'posts_per_page' => 2,

设置cat"=>3"中包含帖子的类别

Set the category from where posts are included in 'cat' => '3'

这篇关于为 WordPress 中的不同页面设置不同的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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