你会这样做的。您的循环基于处于存档或索引页中。(或主页)
$args = array(
\'posts_per_page\' => 3,
\'post_type\' => \'post\', //choose post type here
\'order\' => \'DESC\',
);
// query
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ):
while( $the_query->have_posts() ) : $the_query->the_post();
get_template_part(\'loop\');
endwhile;
else :
endif;
修改后的代码运行完全查询,没有内容部分。php
// WP_Query arguments
$args = array(
\'posts_per_page\' => 3,
\'post_type\' => \'post\', //choose post type here
\'order\' => \'DESC\',
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->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
}
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();
我无法完全测试它,因为您的主题正在调用函数,但请尝试一下。
如果这确实有效,您可以拉出文章内容。替换当前循环中的所有内容。包含上述内容但仅来自
<!-- article -->
至
<!-- /article -->
因为这将在你的新循环中。php,您可以将其从主页中删除。