Wordpress:让用户选择每页显示的帖子数 [英] Wordpress: Let user select the number of posts shown per page

查看:25
本文介绍了Wordpress:让用户选择每页显示的帖子数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个功能,让访问者可以像这样选择每页显示的帖子数量:

I'm trying to build a function where the visitor can select the number of posts shown per page like this:

我从哪里开始以及如何实现这一目标?我目前正在使用 query_post 列出所有帖子:

Where do I start and how do I achieve this? I am currently using query_post to list all the posts:

<?php 
$paged = 1;
query_posts(array( 'showposts'=> 10, 'post_type' => 'post', 'category_name' => 'jobseeker-announcements', 'order' => 'DESC', 'posts_per_page' => 10, 'paged' => get_query_var('paged'))); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post-list">
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <p class="datetime"><span>Date Posted:</span> <?php the_time('m/j/Y'); ?></p>
    <p><?php the_excerpt(); ?></p>
<!--/post-list--></div>
<?php endwhile; ?>

推荐答案

使用 jquery change 函数.

Use jquery change function.

 <?php 
if(isset($_GET['pageVal'])){
  $showposts = esc_sql($_GET['pageVal']);
}else{
  $showposts = 10;
}
    $paged = 1;
    query_posts(array( 'showposts'=> $showposts, 'post_type' => 'post', 'category_name' => 'jobseeker-announcements', 'order' => 'DESC', 'posts_per_page' => $posts_per_page, 'paged' => get_query_var('paged'))); ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="post-list">
        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <p class="datetime"><span>Date Posted:</span> <?php the_time('m/j/Y'); ?></p>
        <p><?php the_excerpt(); ?></p>
    <!--/post-list--></div>
    <?php endwhile; ?>

<select class='page-select'>
<option value='10'>10</option>
<option value='10'>20</option>
<option value='10'>30</option>
</select>
<script>
jQuery.ready(function(){
 $('.page-select').change(function(){
  $(location).attr('href', window.location.href+'?pageVal='+$('.page-select').val());
});
});
</script>

这篇关于Wordpress:让用户选择每页显示的帖子数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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