admin管理员组文章数量:1418659
I'm using the template part below and would like to only show the excerpt after the first 3 posts. The first 3 posts are formatted differently as "header" posts and thus I'd rather not have an excerpt for those posts.
Could someone help me with the PHP?
<div class="content-block-archive">
<div class="content-block-archive-thumbnail">
<a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($post_id, 'large', array('class' => 'alignleft')); ?></a>
</div>
<div class="content-block-archive-meta">
<h2 class="content-block-archive-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="content-block-archive-author"> <?php the_author_posts_link(); ?> | <?php echo get_the_date(); ?>
</div>
<div class="content-block-archive-excerpt"><?php the_excerpt(); ?></div>
</div>
</div>
I'm using the template part below and would like to only show the excerpt after the first 3 posts. The first 3 posts are formatted differently as "header" posts and thus I'd rather not have an excerpt for those posts.
Could someone help me with the PHP?
<div class="content-block-archive">
<div class="content-block-archive-thumbnail">
<a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($post_id, 'large', array('class' => 'alignleft')); ?></a>
</div>
<div class="content-block-archive-meta">
<h2 class="content-block-archive-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="content-block-archive-author"> <?php the_author_posts_link(); ?> | <?php echo get_the_date(); ?>
</div>
<div class="content-block-archive-excerpt"><?php the_excerpt(); ?></div>
</div>
</div>
Share
Improve this question
asked Jul 25, 2019 at 20:54
TnaceTnace
173 bronze badges
1 Answer
Reset to default 0You could add a count variable and count how many times the page has looped and only show the excerpt if the count is 3 or greater.:
<?php
$Count = 0;
?>
<div class="content-block-archive">
<div class="content-block-archive-thumbnail">
<a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($post_id, 'large', array('class' => 'alignleft')); ?></a>
</div>
<div class="content-block-archive-meta">
<h2 class="content-block-archive-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="content-block-archive-author"> <?php the_author_posts_link(); ?> | <?php echo get_the_date(); ?>
</div>
<?php
if ($Count >= 3) { ?>
<div class="content-block-archive-excerpt">
<?php
the_excerpt();
?>
</div>
<?php
}
$Count ++;
?>
</div>
</div>
本文标签: loopOnly Show Excerpt After First 3 Posts
版权声明:本文标题:loop - Only Show Excerpt After First 3 Posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745294872a2652015.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论