当设置偏移量并且在WordPress默认主题中的博客循环中实现了下面给出的Codex解决方案后,分页不起作用

时间:2019-01-25 12:18:40

标签: wordpress

enter image description here我想要博客页面的这种布局 所以我想在顶部显示最近的第一篇文章,在底部显示其余的文章,就像附件的图像一样。为此,我使用了offset = 1,但是由于使用了此功能,我的分页无法正常工作。

请查看下面的代码。 我在index.php中将此代码用于2个自定义循环

<main id="main" class="site-main" role="main">

        <?php
            $args = array(
            'post_type' => 'post',
            'posts_per_page' => 1
        );
        $query = new WP_query ( $args );
        if ( $query->have_posts() ) { ?>

            <section class="books list full-width">

                <?php while ( $query->have_posts() ) : $query->the_post(); ?>

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

                    <div class="left one-third">

                        <?php if ( has_post_thumbnail() ) { ?>

                            <a href="<?php the_permalink(); ?>">

                                <?php the_post_thumbnail( 'medium', array(
                                    'class' => 'left',
                                    'alt'   => get_the_title()
                                    ) );
                                ?>

                            </a>

                        <?php }?>

                    </div>

                    <div class="right two-thirds book-excerpt">

                        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

                    </div>

                    <div class="clear">
                        <?php the_content(); ?>
                    </div>

                    </article>

                <?php endwhile; ?>

                <?php wp_reset_postdata(); ?>

            </section>

        <?php } ?>


        <?php $args = array(
            'post_type' => 'post',
            'offset' => 1
        );
        $query = new WP_query ( $args );
        if ( $query->have_posts() ) { ?>

            <section class="books first wide-box">

                <?php while ( $query->have_posts() ) : $query->the_post();
                    if ( 0 === $wp_query->current_post ) { // Target the first post only
                    // Do what you need to do for the first post only
                    } else {
                        // Display all the other posts as needed   
                    }
                ?>

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

                    <div class="left one-third">

                        <?php if ( has_post_thumbnail() ) { ?>

                            <a href="<?php the_permalink(); ?>">

                                <?php the_post_thumbnail( 'medium', array(
                                    'class' => 'left',
                                    'alt'   => get_the_title()
                                    ) );
                                ?>

                            </a>

                        <?php }?>

                    </div>

                    <div class="right two-thirds book-excerpt">

                        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

                    </div>

                    <div class="clear">
                        <?php the_content(); ?>
                    </div>

                </article>

                <?php endwhile; ?>

                <?php wp_reset_postdata(); ?>

            </section>

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

        <?php } ?>

    </main><!-- #main -->

并实施了https://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination代码,但没有任何解决方案

0 个答案:

没有答案