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

标签 wordpress post pagination

我在 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/

相关文章:

ruby-on-rails - 以 JSON 格式 curl POST 请求

c# - Asp.net 核心问题中的分页,只得到 10 个项目不能让它更快?

mysql - 如何强制 MySQL 中的查询使用索引?

php - 无需提交即可获得值(value)

html - 将 div 大小设置为标题 div 的百分比

PHP session 获取正确值

java - 如何在 Spring 分页中获取下一页

javascript - 在最后一个和下一个按钮之间添加页码、分页

javascript - 无法加载资源: the server responded with a status of 409

mysql - 在列的子选择中计数