gpt4 book ai didi

wordpress - 如何在wordpress中添加自定义分页

转载 作者:行者123 更新时间:2023-12-02 17:32:31 27 4
gpt4 key购买 nike

我在 wordpress 中创建了自定义主题。我想将自定义分页添加到我的自定义帖子模板 INDEX.PHP

你能检查分页脚本有什么问题吗?实际上我已经设置了 4 个帖子限制并且我的博客中有大约 8 个帖子.. 当点击 2 分页时,它不会移动到下一页...

<?php get_header(); ?>

<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;

// WP_Query arguments
$args = array (
'post_type' => the_post(),
'posts_per_page' => '3',
'paged' => $paged
);
?>
<?php

// The Query
$cquery = new WP_Query( $args );
while ( $cquery->have_posts() ) : $cquery->the_post();
?>
<div class="row">
<div class="img"><a href="<?php the_permalink() ?>" class="imgPos"><?php the_post_thumbnail('full'); ?></a></div>
<div class="text">
<h2><a href="<?php the_permalink() ?>" style="color:#545454;"><?php the_title(); ?></a></h2>
<h3 style="line-height: 1px;"><span class="floatL">By &nbsp;</span> <span class="floatL"> <?php the_author_posts_link(); ?> &nbsp;</span> <span class="floatL">&nbsp; - &nbsp;</span> <span class="floatL"><?php the_time('F jS, Y'); ?></span><div class="clr"></div></h3>
<p><?php the_content('Read More') ?></p>

</div>
</div>
<?php
$post->ID;
endwhile;

$big = 999999999; // need an unlikely integer
?>
<div class="row">
<div class="pagination">
<?php
echo paginate_links( array(
'base' => str_replace( $big, '', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $cquery->max_num_pages
) );
?>
</div>
</div>
<?php get_footer(); ?>

请帮忙:)谢谢你,哈沙德帕蒂尔

最佳答案

试试这个

$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;

// WP_Query arguments
$args = array (
'post_type' => 'YOUR_CUSTOM_POST_TYPE',
'posts_per_page' => '3',
'paged' => $paged
);

// The Query
$cquery = new WP_Query( $args );
while ( $cquery->have_posts() ) : $cquery->the_post();
echo $post->ID;
endwhile;

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $cquery->max_num_pages
) );

关于wordpress - 如何在wordpress中添加自定义分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31217677/

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