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>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745294873a4621079.html
评论列表(0条)