简体   繁体   English

WordPress的静态首页搜索分页

[英]Wordpress Static frontpage search pagination

I have a static frontpage on my wordpress website, displaying my posts. 我的wordpress网站上有一个静态首页,显示我的帖子。 Currently it shows 10 posts and I want to make it possible to click "next page" to see the next 10 posts in the query and so on. 当前它显示10个帖子,我希望可以单击“下一页”以查看查询中的下10个帖子,依此类推。 I have tried getting the pagination to work, but it looks like I'm unable to connect it with my search query. 我尝试使分页正常工作,但是好像无法将其与搜索查询连接。

Here is my query: 这是我的查询:

<?php 
query_posts(
array(  'post_type' => 'post',
        'order'     => 'DESC',
        'meta_key' => 'cf_votes',
        'orderby'   => 'meta_value_num',
        'posts_per_page' => 10

)
);
?>

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

<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>

And here is the pagination I have tried: 这是我尝试过的分页:

<?php
global $wp_query;

$big = 999999999;

echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>

So basically I'm able to see the first 10 posts perfectly. 所以基本上我可以完美地看到前10个帖子。 But no alternative to see more posts is shown. 但是没有其他显示更多帖子的替代方法。

Wordpress Codex is pretty comprehensive on the Pagination problem, I recommend you to see this: Wordpress Codex在分页问题上非常全面,我建议您看一下:

http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query

There's a section specifically for the Static Front Page. 有专门针对静态首页的部分。

Something like: 就像是:

<?php 
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }

$args = array(
  'posts_per_page' => 3,
  'paged' => $paged
);

query_posts($args); 

?>

<?php if ( have_posts() ) : ?>

<!-- Add the pagination functions here. -->

<!-- Start of the main loop. -->
<?php while ( have_posts() ) : the_post();  ?>

<!-- the rest of your theme's main loop -->

<?php endwhile; ?>
<!-- End of the main loop -->

<!-- Add the pagination functions here. -->

<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>

<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM