[英]while ( have_posts() ) : the_post(); rendering only 3 posts in archives page : wordpress
[英]Code shows nothing on wordpress: while (have_posts()) {the_post();?>
我已将此代码放入 wordpress 上的 index.php 中,但它没有显示任何内容。 我认为它应该显示所有最新到最新的帖子。 任何人都可以解决这个问题?
<div class="card">
<div class="card-image">
<a href="<?php echo the_permalink(); ?>">
<img src="<?php echo get_the_post_thumbnail_url(get_the_ID); ?>" alt="Card Image">
</a>
</div>
<div class="card-description">
<a href="<?php the_permalink(); ?>">
<h3><?php the_title(); ?></h3>
</a>
<div class="card-meta">
Đăng bởi <?php the_author(); ?> vào <?php the_time('j F, Y') ?> trong <a href="#"><?php echo get_the_category_list(',') ?></a>
</div>
<p>
<?php echo wp_trim_words(get_the_excerpt(), 30); ?>
</p>
<a href="<?php the_permalink(); ?>" class="btn-readmore">Tìm hiểu thêm</a>
</div>
</div>
<?php }
wp_reset_query();
?>
非常感谢。
你几乎错过了一半的循环......
如果您想使用您有问题的帖子模板,那么您可以执行以下操作:
<?php if ( have_posts() ):
$i = 0;
while ( have_posts() ):
$i++;
if ( $i > 1 ):
echo '<hr>';
endif; ?>
<div class="card">
<div class="card-image">
<a href="<?php echo the_permalink(); ?>">
<img src="<?php echo get_the_post_thumbnail_url(get_the_ID); ?>" alt="Card Image">
</a>
</div>
<div class="card-description">
<a href="<?php the_permalink(); ?>">
<h3><?php the_title(); ?></h3>
</a>
<div class="card-meta">
Đăng bởi <?php the_author(); ?> vào <?php the_time('j F, Y') ?> trong <a href="#"><?php echo get_the_category_list(',') ?></a>
</div>
<p>
<?php echo wp_trim_words(get_the_excerpt(), 30); ?>
</p>
<a href="<?php the_permalink(); ?>" class="btn-readmore">Tìm hiểu thêm</a>
</div>
</div>
<?php
endwhile;
endif; ?>
应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.