【发布时间】:2018-07-26 09:43:12
【问题描述】:
我在 Wordpress 的主循环之外创建循环时遇到问题。基本上我想为页面上的所有帖子获取the_excerpt()。代码看起来像这样,但它仍然只为第一篇文章生成摘录。
<?php $i= 0; ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="content-post-wrapper">
<p class="postmetadata"><?php the_category( ', ' ); ?></p>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_author_posts_link(); ?> <?php echo meks_time_ago(); ?></small>
<?php if ( in_category( '16') ) : ?>
<div class="entry-promo">
<div class="img-wrapper-large">
<?php the_post_thumbnail( 'large'); ?>
</div>
<?php echo awesome_excerpt(wp_trim_excerpt(),1); ?>
</div>
<?php else : ?>
<div class="entry">
<div class="img-wrapper-medium">
<?php the_post_thumbnail( 'thumbnail'); ?>
<?php comments_number(); ?>
</div>
<?php if ( $i<99 ) : ?>
<?php the_excerpt(); ?>
<?php endif; ?>
<?php $i=$i+1; ?>
<!--<?php echo awesome_excerpt(wp_trim_excerpt(),1); ?>-->
</div>
<?php endif; ?>
</div>
<?php endwhile; else : ?>
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
我也试过<?php if ( !$post->post_excerpt ) :?>
<!-- Display explicit excerpt-->
<?php the_excerpt(); ?>
<?php endif; ?>,但结果是一样的。 :(
【问题讨论】:
标签: php wordpress wordpress-theming custom-wordpress-pages