WordPress的query_posts分页问题 [英] Wordpress query_posts Pagination issue
本文介绍了WordPress的query_posts分页问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
非常感谢您为我提供的任何见解.
thank you in advanced for any insight I've been scratching my head over this.
这是我用来在首页上发帖的代码:(www.csmpromo.com)
This is the code i'm using to call the posts on the homepage: (www.csmpromo.com)
<div id="home-posts">
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array( 'cat' => 'home', 'types' => $types, 'posts_per_page' => 19, 'paged' => $paged, ) ); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="home-post"><a href="<?php the_permalink(); ?>" class="transition">
<div class="home-image">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('home-thumb', array('class' => 'home-image')); } else { ?>
<img src="<?php bloginfo('template_directory'); ?>/img/fallback.jpg" alt="<?php the_title(); ?>" class="home-image" />
<?php } ?>
</div>
<?php the_titlesmall('', '<i class="icon-right-open-mini"></i>', true, '80') ?></a>
<div class="home-post-meta">
<i class="icon-user" style="font-size:7px; color:#9B362F"></i> <?php the_author_link(array('class' => 'home-author')); ?></span>
<i class="icon-feather" style="font-size:7px; color:#9B362F"></i> <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>
<i class="icon-chat" style="font-size:7px; color:#9B362F"></i> <?php comments_number('0 Comments', '1 Comments', '% Comments' );?></div>
</div>
<?php endwhile; endif; ?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
<?php wp_reset_query(); ?>
</div>
我已经阅读了使用带有分页的query_posts的很多问题,但是我尝试过的每个解决方案都失败了.
I've read there are many issues with using query_posts with pagination but every solutions i've tried has failed.
谢谢!
推荐答案
建议放弃使用query_posts
,保留原始查询在主页上的位置,并使用functions.php
文件修改查询 pre_get_posts
,例如:
It's recommended to abandon the usage of query_posts
, leave the original query on the home page intact, and modify the query from your functions.php
file, using pre_get_posts
, e.g.:
add_action( 'pre_get_posts','so16286638_pre_get_posts' );
function so16286638_pre_get_posts( $query )
{
if( is_home() && $query->is_main_query() ){
$query->set( 'cat', 'home' );
$query->set( 'post_type', 'post' );
// more params
}
return $query;
}
这篇关于WordPress的query_posts分页问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文