簡體   English   中英

WordPress的十一點二十九-強迫PHP代碼跳過首頁上的第一篇文章?

[英]Wordpress Twenty Eleven PhP - forcing php code to skip first post on homepage?

我要解決的問題

我已經設置了Wordpress,以將wordpress Featured Image縮略圖添加到主頁上的所有帖子。

如何使代碼跳過將wordpress Featured Image縮略圖添加到第一篇文章[the_content()〜,在下面的代碼中],而僅將它們添加到wordpress Featured Image縮略圖中,將其他帖子[the_excerpt()〜,在下面的代碼中]?

我在content.php中放入的代碼將wordpress Featured Image縮略圖放在首頁上。 在這里鏈接

    <?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; ?>

這非常簡單-您只需要使用與邏輯相反的邏輯即可確定是顯示完整內容還是僅顯示摘錄。

<?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編碼標准以熟悉它們。 它使閱讀代碼變得更加容易。

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

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

只需驗證是否是第一篇文章

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM