自定义帖子类型的用户存档页面-分页问题

时间:2018-08-21 作者:Tommy

我在写作者。php页面,并显示该用户创建的自定义帖子类型。除了分页以外,一切都很好。有人能告诉我我做错了什么吗?谢谢

<?php get_header(); ?>
<?php if (1 == ($paged = (get_query_var(\'paged\') ?: 1))): ?>
    <section class="posts-container">
        <div class="container">
            <h2 style="text-transform: uppercase;">Posts from <?php echo get_the_author_meta( \'display_name\', $author ); ?></h2>

            <?php
            $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
            $args = array(
                \'post_type\'      => array( \'style\' ),
                \'post_type\'      => array( \'travel\' ),
                \'posts_per_page\' => 1000,
                \'author\'         => $author,
                \'paged\'=>$paged,
            );
            $author_videos = new WP_Query( $args );
            if ( $author_videos->have_posts() ) : while ( $author_videos->have_posts() ) : $author_videos->the_post(); ?>

                <?php get_template_part(\'partials/single\', \'post\'); ?>

            <?php endwhile; ?>

                <div class="clear"></div>

                <div class="nav-previous alignleft">
                    <?php next_posts_link( \'Older posts\' ); ?>
                </div>
                <div class="nav-next alignright">
                    <?php previous_posts_link( \'Newer posts\' ); ?>
                </div>

            <?php wp_reset_postdata(); ?>

            <?php endif; ?>

        </div>
    </section>
<?php endif; ?>

1 个回复
SO网友:benny-ben

你已经试过这种方法了吗?

<section class="posts-container">
    <div class="container">
        <h2 style="text-transform: uppercase;">Posts from <?php echo get_the_author_meta( \'display_name\', $author ); ?></h2>

        <?php
        $args = array(
            \'post_type\'      => array( \'style\', \'travel\' ),
            \'posts_per_page\' => -1,
            \'author\'         => $author
        );

        $author_videos = new WP_Query( $args );
        if ( $author_videos->have_posts() ) : while ( $author_videos->have_posts() ) : $author_videos->the_post(); ?>

            <?php
              // I think you should use archive rather than single
              // get_template_part(\'partials/archive\', \'post\');
                 get_template_part(\'partials/single\', \'post\');
            ?>

        <?php endwhile; ?>

            <div class="clear"></div>

            <div class="nav-previous alignleft">
                <?php next_posts_link( \'Older posts\' ); ?>
            </div>
            <div class="nav-next alignright">
                <?php previous_posts_link( \'Newer posts\' ); ?>
            </div>

        <?php wp_reset_postdata(); ?>

        <?php endif; ?>

    </div>
</section>

结束

相关推荐

防止使用新的Query_Posts()更改

我必须在我的主题首页上显示12项我的自定义帖子类型。但是,当我这样做时,页面标题(<title>...</title>) 更改为Custom Post Type archive - Page Title.因为这是首页,我只想让它有正常的首页标题,即Page title - page tag line. 有没有办法在新的query_posts()? 或者只是为了防止在使用新的query_posts()?我不介意在子页面上发生这种情况,但在首页,当我打开筛选结果时,它不应该改变post