当没有足够的帖子来启用无限滚动按钮时,如何禁用它?
How to disable Infinite Scroll button when there are not enough posts to enable it?
我们正在使用 Infinite Scroll 插件加载分页的 Wordpress 页面。这很好用,但是,当没有足够的帖子来使用 Infinite Scroll 时,我们只剩下 'Load more' 按钮,这显然不是必需的,也没有任何功能。
如何在不需要时隐藏加载更多按钮?我们可以使用 is_paged() 作为条件吗,还是我在 Infinite Scroll 文档中遗漏了什么?
谢谢
JQUERY
// Init infinite scroll
$grid.infiniteScroll({
path: '.pagination .next a',
append: '.articles .article',
outlayer: iso,
loadOnScroll: false,
scrollThreshold: false,
button: '.load-more-button',
hideNav: '.pagination',
status: '.load-status',
history: false,
debug: true
});
HTML
<div class="grid articles">
<?php while ( have_posts() ) : the_post(); ?>
<div class="article">
Article content here!
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div>
<div class="load-more">
<button class="load-more-button">Load More</button>
</div>
<nav class="grid pagination">
<div class="prev"><?php echo get_previous_posts_link('Previous'); ?></div>
<div class="next"><?php echo get_next_posts_link('Next'); ?></div>
</nav>
我知道,这似乎不是一个专业的答案,但它应该有效:
<div class="grid articles">
<?php
$post_counter = 0;
?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
$post_counter++;
?>
<div class="article">
Article content here!
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div>
<?php
if ( $post_counter > 5 ) {
?>
<div class="load-more">
<button class="load-more-button">Load More</button>
</div>
<?php
}
?>
<nav class="grid pagination">
<div class="prev"><?php echo get_previous_posts_link('Previous'); ?></div>
<div class="next"><?php echo get_next_posts_link('Next'); ?></div>
</nav>
所以这是一个简单的 one-time-solution 问题。但是,一个严重的缺点是:您必须在 PHP 模板中对数字进行硬编码。
我们正在使用 Infinite Scroll 插件加载分页的 Wordpress 页面。这很好用,但是,当没有足够的帖子来使用 Infinite Scroll 时,我们只剩下 'Load more' 按钮,这显然不是必需的,也没有任何功能。
如何在不需要时隐藏加载更多按钮?我们可以使用 is_paged() 作为条件吗,还是我在 Infinite Scroll 文档中遗漏了什么?
谢谢
JQUERY
// Init infinite scroll
$grid.infiniteScroll({
path: '.pagination .next a',
append: '.articles .article',
outlayer: iso,
loadOnScroll: false,
scrollThreshold: false,
button: '.load-more-button',
hideNav: '.pagination',
status: '.load-status',
history: false,
debug: true
});
HTML
<div class="grid articles">
<?php while ( have_posts() ) : the_post(); ?>
<div class="article">
Article content here!
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div>
<div class="load-more">
<button class="load-more-button">Load More</button>
</div>
<nav class="grid pagination">
<div class="prev"><?php echo get_previous_posts_link('Previous'); ?></div>
<div class="next"><?php echo get_next_posts_link('Next'); ?></div>
</nav>
我知道,这似乎不是一个专业的答案,但它应该有效:
<div class="grid articles">
<?php
$post_counter = 0;
?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
$post_counter++;
?>
<div class="article">
Article content here!
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div>
<?php
if ( $post_counter > 5 ) {
?>
<div class="load-more">
<button class="load-more-button">Load More</button>
</div>
<?php
}
?>
<nav class="grid pagination">
<div class="prev"><?php echo get_previous_posts_link('Previous'); ?></div>
<div class="next"><?php echo get_next_posts_link('Next'); ?></div>
</nav>
所以这是一个简单的 one-time-solution 问题。但是,一个严重的缺点是:您必须在 PHP 模板中对数字进行硬编码。