Php 完整显示第一篇文章,然后显示截断的文章

Php 完整显示第一篇文章,然后显示截断的文章,php,wordpress,loops,truncate,Php,Wordpress,Loops,Truncate,我正在尝试为我的博客编写一个自定义的默认循环,它将完整显示第一篇文章,然后让下面的文章以截短格式显示,并带有一个特色图像的缩略图。我已经尝试了我所能想到的一切,但无法找到正确解析循环的方法。我尝试了Wordpress论坛上的代码,但都不起作用 <?php if (is_front_page() && ++$count == 1) { the_content(); } else { $excerpt = get_the_excerpt(); echo string

我正在尝试为我的博客编写一个自定义的默认循环,它将完整显示第一篇文章,然后让下面的文章以截短格式显示,并带有一个特色图像的缩略图。我已经尝试了我所能想到的一切,但无法找到正确解析循环的方法。我尝试了Wordpress论坛上的代码,但都不起作用

<?php
if (is_front_page() && ++$count == 1) {
   the_content();
} else {
   $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,80); ?>
}

}


我已经为此工作了好几个星期了。如果有人能帮助我,我将不胜感激。

由于您使用的是“默认”循环,我确信您可以使用此变量,
$current\u post
,它在循环中定义

<?php 
if (is_front_page() && $wp_query->current_post === 1) {
   the_content();
} else {
   $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,80);
} 
?>

试试这个:

<?php $i=0; ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
 <?php $i+=1; ?>
 <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
 <div class="post-date"><?php the_time('F j, Y') ?></div> 
 <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
 <?php if($i<2): the_content(); ?>
 <?php else: ?>
  <?php the_excerpt(); ?>
 ...

...

请显示完整循环,包括while循环不应
$current\u post
be
$wp\u query->current\u post
<?php $i=0; ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
 <?php $i+=1; ?>
 <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
 <div class="post-date"><?php the_time('F j, Y') ?></div> 
 <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
 <?php if($i<2): the_content(); ?>
 <?php else: ?>
  <?php the_excerpt(); ?>
 ...