3 回答
TA贡献1735条经验 获得超5个赞
您需要忘记默认的WordPress循环。请改用WP_Query类查询您的帖子。
$query = new WP_Query([
‘post_type’ => ‘post’,
‘posts_per_page => -1,
]);
// Get the first post
$firstElement = array_shift($query->posts);
// Get the other posts exect first element
$otherPosts = $query->posts;
现在,您需要在模板中循环以创建帖子网格。
TA贡献1951条经验 获得超3个赞
此过程是将标签的类别更改为全角。有很多方法可以做到这一点,但我发现这很简单。首先,从content.php中取出标签并将其放在index.php中。这是为了检查并更改article标签内的类。
<div class="site-main" id="main">
<div class="row no-gutters">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php
// Required variables
$post = $posts[0]; $c=0; ?>
<?php while ( have_posts() ) : the_post(); ?>
<article class="col p-0 <?php $c++; if($c == 1) { echo 'col-12'; }else{ echo 'col-4'; } ?>" <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<?php
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'loop-templates/content', get_post_format() );
?>
</article>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'loop-templates/content', 'none' ); ?>
<?php endif; ?>
</div>
- 3 回答
- 0 关注
- 137 浏览
添加回答
举报