简体   繁体   English

Wordpress 显示页面名称而不是博客文章

[英]Wordpress showing page name instead of blog posts

I'm currently working on my first Wordpress theme and I've a problem:我目前正在开发我的第一个 Wordpress 主题,但遇到了一个问题:

I want to have my last 3 posts on every site.我想在每个网站上都有我的最后 3 个帖子。 Everything works fine on my home page, but when I go to another page it just shows the page name and the "Read more..." tag after it.在我的主页上一切正常,但是当我转到另一个页面时,它只显示页面名称和后面的“阅读更多...”标签。

The code I use is:我使用的代码是:

<?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; ?>

Does anyone know how to fix this issue?有谁知道如何解决这个问题? Thanks in advance!提前致谢!

For displaying posts on other pages, you have to display custom query before while loop.要在其他页面上显示帖子,您必须在 while 循环之前显示自定义查询。

Here is the updated code of your code:这是您的代码的更新代码:

<?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();
?>

May be this would be helpful for you.可能这对你有帮助。

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

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