Wordpress 循环显示限制帖子 [英] Wordpress loop show limit posts

查看:24
本文介绍了Wordpress 循环显示限制帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是基本循环

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

我想在搜索结果页面上显示 20 个帖子.我知道我们可以更改管理面板选项上的值,但它会更改所有内容,即索引页面和存档页面等.我需要以不同的方式使用它们.

I want to show 20 posts on the search results page. I know we can change the value on admin panel options but it will change all i.e. index page and archive page etc. I need to have them differently.

推荐答案

很好的参考:http://codex.wordpress.org/The_Loop

就在调用 while 语句之前,您需要查询帖子.所以:

Just before you call the while statement, you need to query the posts. So:

  <?php query_posts('posts_per_page=20'); ?>

  <?php while (have_posts()) : the_post(); ?>
    <!-- Do stuff... -->
  <?php endwhile;?>

抱歉分页,试试这个:

    <?php 
        global $query_string;
        query_posts ('posts_per_page=20');
        if (have_posts()) : while (have_posts()) : the_post();
    ?>
    <!-- Do stuff -->
    <?php endwhile; ?>

    <!-- pagination links go here -->

    <? endif; ?>

这篇关于Wordpress 循环显示限制帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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