dqlxtv1452 2017-03-25 13:59
浏览 22

分页仅适用于使用categories.php的博客?

I have made a template for my blog page to call in all recent blogs showing 2 blogs per page. I have added a pagination function on the loop but it is just calling the same page over and over and showing the same 2 blog excerpts, even when the url reads /blog/page/2. However when I am clicking the pagination link in blogs that open in the categories archive the pagination works and shows the next 2 blogs? Please help

Template for blog page:

 <?php 

 /*
  *   Template Name: Blog Homepage
 */

get_header()?>
  <main role="main">
    <section>
        <div id="bp-column-L">
        <h1>Our Most Recent Blogs</h1>
        <?php query_posts("posts_per_page=2"); ?>
         <?php get_template_part('loop'); ?>

        </div>

        <?php get_sidebar(); ?>

    </section>
</main>             

</div>

<?php get_footer()?>

The php page for the loop being called:

<?php if (have_posts()): while (have_posts()) : the_post(); ?>

        <!--article-->
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

                <!-- post thumbnail -->
                <?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                <?php the_post_thumbnail(array(120,120)); // Declare pixel size you need inside the array ?>
                        </a>
                <?php endif; ?>
                <!-- /post thumbnail -->

                <!-- post title -->
                <h2>
                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                </h2>
                <!-- /post title -->

                <!-- post details -->
                <span class="date"><?php the_time('F j, Y'); ?> <?php the_time('g:i a'); ?></span>
                <span class="author"><?php _e( 'Published by', 'html5blank' ); ?> <?php the_author_posts_link(); ?></span>
                <span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( 'Leave your thoughts', 'html5blank' ), __( '1 Comment', 'html5blank' ), __( '% Comments', 'html5blank' )); ?></span>
                <!-- /post details -->

                <?php html5wp_excerpt('html5wp_index'); // Build your custom callback length in functions.php ?>

                <?php edit_post_link(); ?>

        </article>


                        <!-- /article -->

<?php endwhile; ?>

        <?php get_template_part('pagination'); ?>
<?php else: ?>

        <!-- article -->
        <article>
                <h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
        </article>
        <!-- /article -->

<?php endif; ?>

And the function being called is:

function html5wp_pagination()
{
    global $wp_query;
$big = 999999999;
echo paginate_links(array(
    'base' => str_replace($big, '%#%', get_pagenum_link($big)),
    'format' => '?paged=%#%',
    'current' => max(1, get_query_var('paged')),
    'total' => $wp_query->max_num_pages
));
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python按要求编写程序
    • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
    • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
    • ¥15 opencv图像处理,需要四个处理结果图
    • ¥15 无线移动边缘计算系统中的系统模型
    • ¥15 深度学习中的画图问题
    • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
    • ¥15 Python报错怎么解决
    • ¥15 simulink如何调用DLL文件
    • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离