wordpress 首页存档页文章数显示不同的三种设置方法

| | Comments (0)



wordpress 首页存档页文章数显示不同的设置方法,大概看了一共有三种方法:

1.直接在wp后台设置即可,后台-reading 设置文章输出数后,首页和存档也输出文章数是一样的,也就是说如果设置的偏小,存档页会显太短,很难看。


2.修改模板代码,利用showposts,当然相对繁琐些但是却是相对最好的。


首页的修改,

找到<?php while (have_posts()) : the_post(); ?>,修改为<?php query_posts('showposts=2'); while (have_posts()) : the_post(); ?>

存档页的修改,这里就不需要了,可以利用后台的设置书直接显示拉

相反,如果首页不需要修改,只根据后台的设置数,那么如果存档也需要另外设置,一样利用showposts来修改,比如代码如下,

<?php
if (is_category()) {
$posts = query_posts($query_string . '&orderby=date&showposts=15');
}
?>

当然通用一些代码如下:


当然,能通过代码解决问题的当然是代码来得简单实用些,把如下代码:

<?php $posts = query_posts($query_string . '&orderby=date&showposts=30'); ?>

添加至category.php、search.php、archive.php或其它页面模板中,以下函数之前:

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

3.利用插件,WordPress插件:Different Posts Per Page

这个插件支持首页、分类页面、标签页面、存档页面以及搜索结果页面设置显示不同的文章,1、2、3、4、5、6都是没有问题的根据自己需要设置。


总结,其实修改代码是自己比较支持的方式,插件方便实用,一样的意思过多的插件wp会负担很重,就跟电脑一样,程序多了就慢了,能减负就减少一些插件。


单点日志:http://spoint.babyshoot.cn


Leave a comment

Archives

Ads by google

Pages

Powered by Movable Type 4.24-en

About this Entry

This page contains a single entry by 单点日志 published on June 26, 2011 9:52 PM.

firefox 5.0 卷豆网的js跳转无效 was the previous entry in this blog.

WordPress 模板首页和目录页摘要、全文输出的修改方法 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.