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 關注
- 180 瀏覽
添加回答
舉報