Javascript 向wordpress帖子列表添加分页
我正在尝试将分页添加到此帖子列表中,我使用的代码是Javascript 向wordpress帖子列表添加分页,javascript,php,wordpress,pagination,Javascript,Php,Wordpress,Pagination,我正在尝试将分页添加到此帖子列表中,我使用的代码是 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/list.js/1.5.0/list.min.js"></script> <!-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/list.js/1.5.0/list.min.js"></script>
<!-- the shortcode to the list -->
...............................
<script>
var myList = new List('main_blog', {
valueNames: ['pis-li'],
page: 3,
pagination: true
});
</script>
...............................
var myList=新列表('main_blog'{
ValueName:['pis-li'],
页码:3,
分页:正确
});
我还尝试了PHP分页代码,并将其添加到我的functions.PHP中
function pagination_nav() {
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) { ?>
<nav class="pagination" role="navigation">
<div class="nav-previous"><?php next_posts_link( '← Older posts' ); ?></div>
<div class="nav-next"><?php previous_posts_link( 'Newer posts →' ); ?></div>
</nav>
<?php }}
函数分页{
全局$wp_查询;
如果($wp\u query->max\u num\u pages>1){?>
我使用的是“DIVI”中的“Extra”主题,帖子列表是通过一个名为“侧边栏中的帖子”的插件制作的。您正在寻找的
分页()函数
如果适用,显示下一组/上一组文章的分页导航
- 来源@
它使用get_the_posts_pagination
和paginate_links()
函数的参数
有关可用参数,请参见get_the_posts_pagination()
- 来源@
- 来源@
分页和循环
如果我没有记错的话,默认情况下,Wordpress将显示12篇文章,然后再显示分页。您正在寻找这个函数
如果适用,显示下一组/上一组文章的分页导航
- 来源@
它使用get_the_posts_pagination
和paginate_links()
函数的参数
有关可用参数,请参见get_the_posts_pagination()
- 来源@
- 来源@
分页和循环
如果我在默认情况下没有记错的话,Wordpress将在显示分页之前显示12篇文章
<?php
if( have_posts() ):
while( have_posts() ): the_post();
echo '<article>';
if( get_the_title() !== '' ):
esc_attr( the_title( '<h1>', '</h1>' ) );
endif;
if( get_the_content() !== '' ):
esc_attr( the_content() );
endif;
echo '<article>';
endwhile;
/**
* the_posts_pagination
* Displays a paginated navigation to next/previous set of posts, when applicable.
* @link https://developer.wordpress.org/reference/functions/the_posts_pagination/
* @link https://developer.wordpress.org/reference/functions/get_the_posts_pagination/
* @link https://developer.wordpress.org/reference/functions/paginate_links/
*/
the_posts_pagination( array(
'screen_reader_text' => ' ',
'prev_text' => '←',
'next_text' => '→',
'show_all' => true,
) );
else:
echo 'No posts yet!';
endif; ?>