gpt4 book ai didi

php - 如何在自定义页面或模板中为 WordPress 帖子创建分页

转载 作者:行者123 更新时间:2023-12-05 06:42:53 26 4
gpt4 key购买 nike

我用这个方法

$args = array(
'posts_per_page' => 4,
'offset' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'suppress_filters' => true);

$recent_postss = wp_get_recent_posts($args, ARRAY_A);
?>

foreach ($recent_postss as $posts) { }

现在我想为此创建一个分页。我已经尝试了很多,但对我没有任何用处。我应该如何修改此代码以创建分页?

最佳答案

试试这个它正在为自定义帖子工作

$args = array(
'posts_per_page' => 4,
'offset' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'paged' => (get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1),
'suppress_filters' => true);

用于分页链接

$argsp = array(
'base' => '%_%',
'format' => '?paged=%#%',
'total' => 5,
'current' => 2,
'show_all' => false,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => true,
'prev_text' => __('« Previous'),
'next_text' => __('Next »'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => ''
);


echo paginate_links( $argsp );

关于php - 如何在自定义页面或模板中为 WordPress 帖子创建分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35693805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com