[英]Wordpress showing page name instead of blog posts
我目前正在开发我的第一个 Wordpress 主题,但遇到了一个问题:
我想在每个网站上都有我的最后 3 个帖子。 在我的主页上一切正常,但是当我转到另一个页面时,它只显示页面名称和后面的“阅读更多...”标签。
我使用的代码是:
<?php while(have_posts()) : the_post(); ?>
<div class="article-preview">
<p>» <?php the_time('l, j. F Y')?></p>
<b><?php the_title(); ?></b>
<?php the_excerpt(); ?><a href="<?php echo get_permalink(); ?>" style="color:white"> Mehr...</a>
<hr style="margin-top:5px" />
</div>
<?php endwhile; ?>
有谁知道如何解决这个问题? 提前致谢!
要在其他页面上显示帖子,您必须在 while 循环之前显示自定义查询。
这是您的代码的更新代码:
<?php $the_query = new WP_Query( 'post_type'=>'post', 'posts_per_page=3' ); ?>
// Start our WP Query
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="article-preview">
<p>» <?php the_time('l, j. F Y')?></p>
<b><?php the_title(); ?></b>
<?php the_excerpt(); ?><a href="<?php echo get_permalink(); ?>" style="color:white"> Mehr...</a>
<hr style="margin-top:5px" />
</div>
<?php endwhile;
wp_reset_postdata();
?>
可能这对你有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.