繁体   English   中英

while ( have_posts() ) : the_post(); 在档案页面中仅呈现 3 个帖子:wordpress

[英]while ( have_posts() ) : the_post(); rendering only 3 posts in archives page : wordpress

循环无法正常工作时的存档页面。 该特定类别已发布 5 个帖子。 但是当我导航到该类别的档案页面时,它只显示 3 个帖子。

尝试使用显示该特定类别的帖子数

$count = $GLOBALS['wp_query']->found_posts;

它正在返回正确的帖子数(总共 5 个帖子)。 但是当继续 while 循环have_posts()它只显示 3。

endwhile后尝试wp_reset_query ,但没有奏效。 还尝试使用get_categories()函数来显示每个类别中的计数数量,它返回正确的计数,但在 while 循环中仅显示 3 个帖子。

下面是archive.php 代码。

<div class="row">

<?php
while (have_posts()):
    the_post();
?>
    <div class="col-sm-12 col-md-8">
        <div class="blog-post small">
            <div class="post-header">
                <p class="categories"><a href="#"><?php the_category(', ') ?></a></p>

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

                <ul class="post-meta">
                    <li class="date"><?php the_time('F jS, Y') ?></li>
                    <li class="author">by <a href="<?php the_permalink() ?>"><?php the_author_posts_link(); ?> </a></li>
                    <li class="comments"><a href="<?php the_permalink() ?>"><?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></a></li>
                </ul>
            </div>

            <div class="post-cover">
<?php
    $post_id = get_the_ID();

    $meta_info = get_post_meta($post_id, '_thumbnail_id', true);
    $image = wp_get_attachment_image_src($meta_info, $size = 'full', $icon = false);
?>
                <a href="<?php the_permalink(); ?>">
    
                    <img width="367" height="346" src="<?php echo $image[0]; ?>" alt="simple post cover" />
                </a>
            </div>
    
            <div class="post-body">
                <p><?php the_excerpt(); ?></p>
    
                <div class="align-center">
                    <a href="<?php the_permalink() ?>" class="btn template-btn-2">Read more</a>
                </div>
            </div>
        </div>
    </div>

<?php
endwhile;
?>
</div>

我该怎么办? 有什么想法吗?

如果您仍然需要,请尝试这样做:-)

<?php query_posts('showposts=3'); if (have_posts()) : while (have_posts()) : the_post(); ?>

    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    <p>?php the_time(); ?></p>
    <?php the_content(); ?>
    <p><?php the_tags(); ?></p>

<?php endwhile;?>

    <p><?php next_posts_link(); ?></p>
    <p><?php previous_posts_link(); ?></p>

<?php else : ?>

    <h1>Not Found</h1>
    <p>Silly monkey.</p>

<?php endif; wp_reset_query(); ?>

如果在某人的博客中发现了这个,但也许是谁使用了这个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM