【发布时间】:2019-11-02 13:10:49
【问题描述】:
我是 WordPress 新手,我创建了一个自定义模板,当我尝试将帖子提取到首页(主页)时遇到问题。
在(仪表板->阅读)中,我将主页显示设置为静态页面,并选择主页为(主页)和发布页面为(帖子)。
在 index.php 中显示帖子页面中帖子的代码是:
<section class="recent-posts" id="recent-posts">
<div class="container">
<div class="title text-center">
<h1 class="title-blue">posts</h1>
</div>
<div class="row">
<?php
while(have_posts()) {
the_post();
?>
<div class="col-lg-6">
<div class="single-rpost d-sm-flex align-items-center" data-aos="fade-right"
data-aos-duration="800">
<div class="post-thumb">
<img class="img-fluid" src="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>" alt="post-1">
</div>
<div class="post-content text-sm-right">
<time datetime="<?php the_time('l, jS/n/Y'); ?>">
<?php the_time('l, jS/n/Y'); ?>
</time>
<h3>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<p class="post-excerpt">
<?php echo wp_trim_words(get_the_excerpt(), 10); ?>
</p>
<p>
<!-- <a href="#"> -->
<?php echo get_the_category_list(' ') ?>
<!-- </a> -->
</p>
<a class="post-btn" href="<?php the_permalink(); ?>">
<i class="fa fa-arrow-left"></i>
</a>
</div>
</div>
</div>
<?php
}
wp_reset_query();
?>
</div>
<!-- Posts Navigation -->
</div>
</section>
<!-- Paginate through pages -->
<div class="pagination">
<?php echo paginate_links(); ?>
</div>
它在帖子页面中工作正常,但是当我在 page-home.php 文件中复制相同的代码时它不起作用并且根本没有获取任何帖子。
对不起,我是初学者,但我需要帮助。 谢谢。
【问题讨论】:
标签: php wordpress custom-wordpress-pages