【问题标题】:How to paginate using Divs instead of Posts?如何使用 Divs 而不是 Posts 进行分页?
【发布时间】:2015-03-12 19:17:10
【问题描述】:

我有一个简单的模板页面,我刚刚添加到我的网站,并且每个月都会手动添加新的时事通讯的部门。但是,当我收到很多时事通讯时,将要查看该页面的用户将不得不继续向下滚动才能找到时事通讯。

<?php get_header();?>
<div id="main" class="defaultContentWidth">
<div id="wrapper-row">
<div id="primary">
    <div id="content">
<?php the_breadcrumb();?>
        <h1 class="entry-title"><?php the_title();?></h1>
        <?php if(have_posts()) :
      while(have_posts()) : the_post();?>
        <div class="newscont"><?php the_content();?></div>
      <?php endwhile;
        endif;?>

        <div class="contnewslist">
        <div class="newsblock">
            <h2>NEWSLETTER 1</h2>
            <i>December 01, 2014</i>
            <p>This is the December edition of the newsletter. Featuring in this newsletter is ...</p>
            <input type="submit" value="Download" id="download" class="newsdownload">
        </div>
        <div class="newsblock">
            <h2>NEWSLETTER 2</h2>
            <i>January 01, 2015</i>
            <p>This is the January edition of the newsletter. Featuring in this newsletter is ...</p>
            <input type="submit" value="Download" id="download" class="newsdownload">
        </div>
        </div>

     </div>
  </div>
 </div>
</div>
<?php get_footer();?>

因此,我想知道如何在页面上添加基本的分页 'Previous 1 2 Next' 按钮,并将时事通讯的分区数量限制在每页大约五个,记住 这些不是帖子

编辑 1

我需要知道如何计算 div 的数量,将其限制为每页 5 个 div,并根据通讯 div 的数量生成更多页面!

我想要的分页示例是 -

【问题讨论】:

  • 我看到你已经标记了wordpress,没有插件可以做到这一点吗?到目前为止你尝试过什么?
  • @Billy 我发现了一些提供分页等的插件......但老实说,我发现的那些是基于分页帖子的,因此我强调我没有使用帖子!
  • 来自 DB 或硬编码到 html 中的 div 在哪里?如果是数据库,那么 Google 上有很多教程
  • @Billy 它们被硬编码到 html 中,但是如果使用硬代码完成分页要困难得多,那么我也许可以考虑将其更改为 DB。
  • 将所有 div 分组到一个容器中,并将溢出隐藏和空白设置为 no-wrap,然后每 5 个元素分组到另一个 div 中,该 div 将充当您的页面。使这些页面内联块与容器的宽度相同。然后,您可以根据它们需要在哪个页面上向左或向右动画块。然后在底部创建分页链接很容易,只要您跟踪它们所在的页面即可。

标签: php html wordpress pagination


【解决方案1】:

我认为如果它们在数据库中,最好的方法是使用 PHP 和 Jquery 分页。例如,假设您有 100 份时事通讯,您可以像本教程 PHP Tutsplus tutorial on pagination 那样使用 php 分页来完成,并将其分成 5 份,如果时事通讯很大,请采用这种方式。缺点是每次页面更改都会调用服务器。如果时事通讯相当小,那么混合 jquery,让 php 计算总数,传递前 15 或 20 个,让 jquery 将它们分成 5 个,在加载第 5 页时可能会调用 ajax 来获取下一个 15 .jquery 将能够处理该问题并在请求第 6 页无缝更新 div 时添加 onclick jquery分页插件可以找到here, sitepoint

【讨论】:

  • 谢谢,如果我需要任何进一步的帮助,我会尽快回复您!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-28
  • 1970-01-01
  • 2019-08-05
  • 2021-05-24
  • 1970-01-01
  • 2021-10-23
  • 1970-01-01
相关资源
最近更新 更多