サポート » 使い方全般 » トップページにブログの新着記事を全文表示させたい

  • 解決済 saisola

    (@saisola)


    wordpress3.8、テーマはResponsiveを使用しています。

    別のフォーラムテーマでも質問させていただいたのですが、もしかしたらカテゴリ違いかと思いこちらでも質問させていただきます。
    ttp://ja.forums.wordpress.org/topic/41354?replies=2

    トップページにブログ投稿の最新記事を1件のみ全文表示させたいのですが、
    思うようにできず困っています。
    なお、通常のブログページには3件分表示されるように設定しています。

    今使用しているテーマだとトップページがindex.php、ブログの記事一覧がhome.phpなので、home.phpの中身をindex.phpにまるごと書き写し、以下の一文を加えて試しました。
    <?php query_posts('posts_per_page=1'); ?>

    すると最新の投稿記事は表示できたのですが、今度はトップページの記事がループしてしまいます。
    どの部分をどう変更すればいいのかがわからず手詰まり状態です。
    解決策がお分かりになるようでしたらご教授ください。

    以下がindex.phpに記載したhome.php内のコードです。

    <?php get_template_part( 'loop-header' ); ?>
    <?php query_posts('posts_per_page=1'); ?>
    		<?php if( have_posts() ) : ?>
    
    			<?php while( have_posts() ) : the_post(); ?>
    
    				<?php responsive_entry_before(); ?>
    				<div id="post-<?php the_ID(); ?>" <?php post_class(); ?> >
                    <div class="grid col-460t">
    					<?php responsive_entry_top(); ?>
    					<?php get_template_part( 'post-meta' ); ?>
    					<div class="post-entry">
    						<?php if( has_post_thumbnail() ) : ?>
    							<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    								<?php the_post_thumbnail(); ?>
    							</a>
    						<?php endif; ?>
    						<?php the_content( __( 'Read more ›', 'responsive' ) ); ?>
    						<?php wp_link_pages( array( 'before' => '<div class="pagination">' . __( 'Pages:', 'responsive' ), 'after' => '</div>' ) ); ?>
    					</div>
                        </div>
    					<!-- end of .post-entry -->
    
    					<?php get_template_part( 'post-data' ); ?>
    
    					<?php responsive_entry_bottom(); ?>
    				</div><!-- end of #post-<?php the_ID(); ?> -->
    				<?php responsive_entry_after(); ?>
    
    			<?php
    			endwhile;
    
    			get_template_part( 'loop-nav' );
    
    		else :
    
    			get_template_part( 'loop-no-posts' );
    
    		endif;
    		?>
2件の返信を表示中 - 1 - 2件目 (全2件中)
  • 全文記事の表示ではありませんが、私はこのようにしております。

    <dl>
     <?php
       $new_posts = get_posts( array(
    /*    'category_name' => 'news', //特定のカテゴリースラッグを指定*/
        'posts_per_page' => 1 //取得記事件数
      ));
        foreach( $new_posts as $post ):
        setup_postdata( $post );
     ?>
     <dt><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dt>
     <dd>
     <?php the_time('Y年n月j日'); ?>
    
    <?php the_post_thumbnail();	/* アイキャッチ */ ?>
    <?php the_excerpt(); ?>
    <a class="more-link" href="<?php the_permalink(); ?>">続きを読む>></a>
     </dd>
    <?php
      endforeach;
      wp_reset_postdata();
    ?>
    </dl>

    ご参考までに。

    トピック投稿者 saisola

    (@saisola)

    builder0xxさん

    ありがとうございます。あまり知識のない私でもわかりやすいコードです。
    参考にさせてもらいます。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「トップページにブログの新着記事を全文表示させたい」には新たに返信することはできません。