如何在wordpress中添加自定义分页 [英] How to add Custom pagination in wordpress

查看:47
本文介绍了如何在wordpress中添加自定义分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

<?php get_header();?><?php$paged = ( get_query_var( 'paged' ) ) ?absint(get_query_var('paged')):1;//WP_Query 参数$args = 数组 ('post_type' =>the_post(),'posts_per_page' =>'3','分页' =>$分页);?><?php//查询$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">作者&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('阅读更多') ?></p>

<?php$post->ID;终了;$big = 999999999;//需要一个不太可能的整数?><div class="row"><div class="分页"><?php回声分页链接(数组('基础' =>str_replace( $big, '', esc_url( get_pagenum_link( $big ) ) ),'格式' =>'?paged=%#%','当前' =>max( 1, get_query_var('paged') ),'总计' =>$cquery->max_num_pages) );?>

<?php get_footer();?>

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

解决方案

试试这个

$paged = ( get_query_var( 'paged' ) ) ?absint(get_query_var('paged')):1;//WP_Query 参数$args = 数组 ('post_type' =>'YOUR_CUSTOM_POST_TYPE','posts_per_page' =>'3','分页' =>$分页);//查询$cquery = new WP_Query( $args);while ( $cquery->have_posts() ) : $cquery->the_post();echo $post->ID;终了;$big = 999999999;//需要一个不太可能的整数回声分页链接(数组('基础' =>str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),'格式' =>'?paged=%#%','当前' =>max( 1, get_query_var('paged') ),'总计' =>$cquery->max_num_pages) );

i have created custom theme in wordpress. I want to add custom pagination to my custom post template which is INDEX.PHP

Can you please check what is wrong in pagination script. actually i have set 4 post limit and there around 8 posts in my blog.. when click on 2 pagination, it won't move to next page...

<?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(); ?>

Please help :) Thank you, Harshad Patil

解决方案

Try this

$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中添加自定义分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆