funbsd 2008-10-5 08:59
加了query_posts后不能分页,Live Writer不能下载样式模板
我在index.php里<?php if (have_posts()) : ?>前面加了<?php query_posts($query_string . "&category_name=tech") ?>后,用Windows Live Writer更新样式时出错,不能下载样式模板了,去掉就没问题了,为什么?
另外我用复制index.php,新建了一个页面模板,但是用这个模板新建的页显示的日志多了的话不能分页,点下一页显示的还是第一页。index.php就没这个问题。
funbsd 2008-10-5 15:53
另外,有没有好用点的日志分页插件(是nextpage的分页,不是日志列表分页),wp_link_pages不咋好用
funbsd 2008-10-5 15:56
还有,get_avatar这个函数怎么改成从本地获得图片?而不是在评论里显示[url]http://www.gravatar.com/avatar[/url]上的图片?
funbsd 2008-10-6 09:47
RSS怎么按分类订阅?url怎么写?(已解决)
[[i] 本帖最后由 funbsd 于 2008-10-6 19:06 编辑 [/i]]
funbsd 2008-10-6 19:07
后边的问题我已经解决了,前边俩问题有人回答一下吗?
funbsd 2008-10-10 11:28
找到解决方法了,这个问题也不是很复杂,咋就没人回答呢?这儿人气真是不行啊。
WordPress codex上说query_posts只适合用在主页,如果其他页要自己写WP_Query
[code]The query_posts function is intended to be used to modify the main page Loop only.
It is not intended as a means to create secondary Loops on the page.
If you want to create separate Loops outside of the main one, you should create separate WP_Query objects and use those instead.[/code]
我刚开始接触wordpress,不知道WP_Query怎么写,觉得可能挺麻烦,所以总想找捷径
终于在wordpress forum找到这个办法:
[code]<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php query_posts("category_name=life&paged=$paged"); ?>[/code]
[font=Consolas]刚找到这个办法,就看到了[/font][font=Helvetica]WP_Query怎么写,其实也挺简单:[/font]
[code]
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query("category_name=life&paged=$paged");
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php $wp_query = null; $wp_query = $temp;?>[/code]
[[i] 本帖最后由 funbsd 于 2008-10-10 11:31 编辑 [/i]]
funbsd 2008-10-10 11:42
最后发现,其实只要加上paged参数就可以了:
[code]<?php query_posts("category_name=life&paged=$paged"); ?>[/code]
前边获得paged参数的那行可以不要,那行可能是在不能获取paged参数的地方用的,也可能是原来版本的bug
这么点问题折腾了我差不多俩星期,唉~:( :( :(