我正在尝试在我的主页上加载3篇最新的帖子。我完全是个新手,但我似乎正在进步。
这是我的代码(如下)。现在每篇帖子都有一个标题“主页”,我知道这是因为主页是主要的查询?
<?php
$latest_blog_posts = new WP_Query( array( \'posts_per_page\' => 3 ) );
if ( $latest_blog_posts->have_posts() ) : while ( $latest_blog_posts->have_posts() ) : $latest_blog_posts->the_post();
get_template_part(\'loop\');
endwhile; endif;
?>
那么,我该如何修改这段代码,以便它使用循环从博客中获取3篇最新的帖子呢。php?我还有一个自定义的帖子类型,它使用不同的页面/循环。但我假设,一旦这项工作开始,就只需要将“循环”替换为“循环2”,以便使用相同的代码来实现这项工作?
希望有人能帮上忙。对我来说,一分钟前一步,一分钟后两步!
EDIT
目录loop.php
应回复要求:)<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- post thumbnail -->
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="h-entry__image-link">
<?php the_post_thumbnail(array(120,120)); // Declare pixel size you need inside the array ?>
</a>
<?php endif; ?>
<!-- /post thumbnail -->
<!-- post title -->
<h2 class="p-name">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<!-- /post title -->
<!-- post details -->
<time datetime="<?php the_time(\'Y-m-j\'); ?>" class="dt-published"><?php the_time(\'jS F Y\'); ?></time>
<!-- /post details -->
<?php html5wp_summary(\'html5wp_index\'); // Build your custom callback length in functions.php ?>
<p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="arrow-link">Read the full article</a></p>
<?php edit_post_link(); ?>
</article>
<!-- /article -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( \'Sorry, nothing to display.\', \'html5blank\' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>