尝试在首页上每页加上一个帖子时,第二页不存在

时间:2018-08-13 05:50:49

标签: wordpress-theming

我创建了一个代码,将主页分成多个页面。默认情况下,每页的帖子数设置为5。但是当我尝试打开第二页时,它显示404错误。我的index.php文件如下所示:

    <div id="primary" class="content-area">
        <main id="main" class="site-main">

        <?php
        $homepage_posts = 3;
        query_posts('posts_per_page='. apply_filters('change_number_of_posts_shown', $homepage_posts));
 if(have_posts()):

            if ( is_home() && ! is_front_page() ) :
                ?>
                <header>
                    <h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
                </header>
                <?php
            endif;

            /* Start the Loop */
            while ( have_posts() ) :
                the_post();

                /*
                 * Include the Post-Type-specific template for the content.
                 * If you want to override this in a child theme, then include a file
                 * called content-___.php (where ___ is the Post Type name) and that will be used instead.
                 */
                get_template_part( 'template-parts/content-excerpt', get_post_type() );

            endwhile;

            the_posts_pagination( array(
                    'prev_text' => openblogger_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'openblogger' ) . '</span>',
                    'next_text' => '<span class="screen-reader-text">' . __( 'Next page', 'openblogger' ) . '</span>' . openblogger_get_svg( array( 'icon' => 'arrow-right' ) ),
                    'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'openblogger' ) . ' </span>',
                ) );

        else :

            get_template_part( 'template-parts/content', 'none' );

        endif;
        ?>

        </main><!-- #main -->
    </div><!-- #primary -->

如您所见,我正在定义分页。帖子数设置为5,但尝试打开下一页时显示404错误。希望你能理解。 预先感谢。

0 个答案:

没有答案