2013-11-09 76 views
1

What I want to fixWordpress Twenty Eleven PhP - 強制PHP代碼跳過主頁上的第一篇文章?

我已經建立了我的Wordpress,將wordpress Featured Image thumbnails添加到主頁上的所有帖子。

如何讓代碼跳過將wordpress Featured Image thumbnails添加到第一篇文章[the_content()〜在下面的代碼中],並且只將它們添加到wordpress Featured Image thumbnails其他文章[the_excerpt()〜在下面的代碼中]?

代碼我把content.php放在主頁上放wordpress Featured Image thumbnailsLink Here

<?php if (is_search() | is_home()) : // Edit this to show excerpts in other areas of the theme?> 
    <div class="entry-summary"> 
    <!-- This adds the post thumbnail/featured image --> 
     <div class="excerpt-thumb"><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'twentyeleven'), the_title_attribute('echo=0')); ?>" rel="bookmark"> 
    <?php the_post_thumbnail('excerpt-thumbnail', 'class=alignleft'); ?></a></div> 
         <?php if($wp_query->current_post == 0 && !is_paged()) { the_content(); } else { the_excerpt(); }  ?>      


      </div><!-- .entry-summary --> 
      <?php else : ?> 
      <div class="entry-content"> 
        <?php the_content(__('Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven')); ?> 
        <?php wp_link_pages(array('before' => '<div class="page-link"><span>' . __('Pages:', 'twentyeleven') . '</span>', 'after' => '</div>')); ?> 
      </div><!-- .entry-content --> 
      <?php endif; ?> 

回答

0

定義一個計數器並首次不顯示特色圖像。

<?php $counter++; if ($counter!=1) the_post_thumbnail('excerpt-thumbnail', 'class=alignleft'); ?> 
0

只是驗證,如果是第一次發帖或不

$firstPost = true; 
while() // loop for posts 
if(!$firstPost){ 
//your code for adding thumbnail 
} 
else{ 
$firstPost = false; 
} 
+2

請不要忘記注意事項 – user2284570

1

這很簡單 - 你只需要使用您按順序使用邏輯相反弄清楚是否顯示全部內容或只摘錄。

<?php if (is_search() || is_home()) : // Edit this to show excerpts in other areas of the theme?> 
    <div class="entry-summary"> 
     <?php if ($wp_query->current_post != 0 || is_paged()) : // Don't display the thumbnail if it's the first post... ?> 
      <!-- This adds the post thumbnail/featured image --> 
      <div class="excerpt-thumb"> 
       <a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'twentyeleven'), the_title_attribute('echo=0')); ?>" rel="bookmark"> 
        <?php the_post_thumbnail('excerpt-thumbnail', 'class=alignleft'); ?> 
       </a> 
      </div> 
     <?php endif; ?> 
     <?php if ($wp_query->current_post == 0 && ! is_paged()) { 
      the_content(); 
     } else { 
      the_excerpt(); 
     } ?> 
    </div><!-- .entry-summary --> 
<?php else : ?> 
    <div class="entry-content"> 
     <?php the_content(__('Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven')); ?> 
     <?php wp_link_pages(array('before' => '<div class="page-link"><span>' . __('Pages:', 'twentyeleven') . '</span>', 'after' => '</div>')); ?> 
    </div><!-- .entry-content --> 
<?php endif; ?> 

PS:我知道這是相當無關,但請,請嘗試有一個更乾淨的代碼:)看看在WordPress PHP Coding Standards來熟悉它們。它使得通過代碼閱讀變得更容易。

相關問題