首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >旧的帖子和更新的Wordpress代码不在我的博客页面上工作

问旧的帖子和更新的Wordpress代码不在我的博客页面上工作
EN

Stack Overflow用户
提问于 2015-07-01 00:48:16
回答 1查看 657关注 0票数 0

我有一个网站,在那里,我起诉wordpress代码,以放置较旧的帖子和更新的帖子,但它不会有效果。我不太擅长调试代码。有人能帮帮我吗。我也读过很多关于这方面的文章和帖子,但是我没有得到回答,希望有人能帮助我。非常感谢

代码语言:javascript
复制
<div id="main" class="blog-list-page">
    <div class="container">
        <div class="section">
            <?php while ( have_posts() ) : the_post(); ?>
                <article <?php post_class(); ?>>
                    <header class="page-header">
                        <!--<h1 class="page-title"><?php //the_title(); ?></h1>-->
                    </header>
                    <div class="entry-content">
                        <?php the_content(); ?>
                    </div>
                </article>
            <?php endwhile; ?>
        </div>
        <div class="section blog-posts-list">
            <?php
                $args = [
        'posts_per_page'   => 10,
                    'offset'  => 0,
                    'orderby' => 'post_date',
                    'order'   => 'DESC',
                    'post_type' => 'post',
                    'post_status' => 'publish',
                ];
                $posts= get_posts( $args );

                foreach ( $posts as $post ) :
                    setup_postdata($post);
            ?>

            <article class="clearfix">
                <div class="post-category">
                    <?php
                        $categories = get_the_category();
                        echo $categories[0]->name;
                    ?>
                </div>
                <a href="<?= the_permalink(); ?>">
                    <h2><?php the_title(); ?></h2>
                </a>
                <div class="meta">
                    <span class="author"></span>
                    <span class="timestamp"></span>
                </div>
                <?php if (has_post_thumbnail()) : ?>
                    <a href="<?= the_permalink(); ?>" class="post-thumbnail">
                        <?= the_post_thumbnail(); ?>
                    </a>
                <?php endif; ?>
                <div class="excerpt">
                    <?php the_excerpt(); ?>
                </div>
                <div>
                    <a href="<?= the_permalink(); ?>" class="read-more-link">Read more...</a>
                </div>
            </article>

            <?php
                endforeach;
            ?>

        </div>

    </div>
</div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-01 06:22:04

不要将get_posts用于分页查询,因为它不是用于分页查询的。get_posts通过将no_found_rows=true传递给WP_Query,合法地打破了分页,以加快非分页查询。而且,get_posts只从WP_Query对象返回$posts属性,因此这一切都使得对get_posts的分页完全是一场噩梦。

对于分页查询,您应该使用WP_Query。

额外资源

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31150866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档