1

修正したいこと

ホームページのすべての投稿にワードプレスのアイキャッチ画像のサムネイルを追加するようにワードプレスを設定しました。

最初の投稿 [the_content() ~ 以下のコード] への wordpress の注目の画像のサムネイルの追加をスキップし、他の投稿 [the_excerpt() ~ 以下のコードの] のwordpress の注目の画像のサムネイルにのみ追加するコードを作成するにはどうすればよいですか?

content.php に入れて、ワードプレスの注目の画像のサムネイルをホームページに配置するコード。リンクはこちら

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

3 に答える 3

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を参照して、よく理解してください。コードを読むのがずっと簡単になります。

于 2013-11-09T22:37:51.253 に答える
0

カウンターを定義し、初めて注目の画像を表示しません。

<?php $counter++; if ($counter!=1) the_post_thumbnail('excerpt-thumbnail', 'class=alignleft'); ?>
于 2013-11-09T19:31:10.353 に答える
0

最初の投稿かどうかを確認するだけです

$firstPost = true;
while() // loop for posts
if(!$firstPost){
//your code for adding thumbnail
}
else{
$firstPost = false;
}
于 2013-11-09T19:33:25.397 に答える