サポート » テーマ » ページャーが表示されない

  • 解決済 erenae

    (@erenae)


    初めまして!

    最近wordpressの勉強をはじめたものです。
    高橋のりさん著の『基礎からのwordpress』を用いて勉強しているのですが、原因のわからない処理が起こってしまっているので、質問したいと思います。

    著作で配布されている「simplesimple」というテーマを利用しているのですが、アイキャッチ画像がない場合の処理を行なうコードを入力するセクションで問題が起こりました。

    わかりやすくするために変更前と変更後のコードを貼り付けます。
    index.phpです。34行目~辺りをif文に変更しています。

    【問題点】
    変更後、①指定したアイキャッチ画像が設定されていない場合の画像が表示されない。②ページャーとサイドバーのカテゴリーやポストデータなどが消えてしまう。もともとは一ページに3つ表示されていた記事が二つしか表示されない。
    変更前は、問題なくアイキャッチ画像がある場合にもアイキャッチ画像は表示されます。

    【変更前】

    <?php
    /****************************************
    
    	index.php
    
    	WordPressサイトには、なくてはならない
    	テンプレートファイルです。
    
    	index.php のコードに関しては、
    	CHAPTER 9 で詳しく解説しています。
    
    *****************************************/
    
    get_header(); ?>
    <!-- index.php -->
    <div id="main">
    	<?php if ( have_posts() ) : // WordPress ループ
    		while ( have_posts() ) : the_post(); // 繰り返し処理開始 ?>
    			<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    				<div class="content-box">
    					<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    					<p class="post-meta">
    						<span class="post-date"><?php the_date(); /* echo get_the_date() に書き換える(CHAPTER 9) */ ?></span>
    						<span class="category">Category - <?php the_category( ', ' ) ; ?></span>
    						<span class="comment-num"><?php comments_popup_link( 'Comment : 0', 'Comment : 1', 'Comments : %' ); ?></span>
    					</p>
    
    					<?php the_excerpt();?>
    					<p class="more-link">
    						<a href="<?php the_permalink(); ?>"
    						title="「<?php the_title(); ?>」の続きを読む">続きを読む »</a>
    					</p>
    				</div>
    				<p class="thumbnail-box">
    
    						<?php the_post_thumbnail("thumbnail"); ?>
    					</p>
    
    			</div>
    
    		<?php endwhile; // 繰り返し処理終了
    	else : // ここから記事が見つからなかった場合の処理 ?>
    			<div class="post">
    				<h2>記事はありません</h2>
    				<p>お探しの記事は見つかりませんでした。</p>
    			</div>
    	<?php endif;?>
    
    	<?php if ( $wp_query->max_num_pages > 1 ) : // ここからページャー ?>
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link( '« PREV' ); ?></div>
    			<div class="alignright"><?php previous_posts_link( 'NEXT »' ); ?></div>
    		</div>
    	<?php endif; // ページャーここまで ?>
    
    </div><!-- /main -->
    <!-- / index.php -->
    <?php get_sidebar();
    get_footer(); ?>

    【変更後】

    <?php
    /****************************************
    
    	index.php
    
    	WordPressサイトには、なくてはならない
    	テンプレートファイルです。
    
    	index.php のコードに関しては、
    	CHAPTER 9 で詳しく解説しています。
    
    *****************************************/
    
    get_header(); ?>
    <!-- index.php -->
    <div id="main">
    	<?php if ( have_posts() ) : // WordPress ループ
    		while ( have_posts() ) : the_post(); // 繰り返し処理開始 ?>
    			<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    				<div class="content-box">
    					<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    					<p class="post-meta">
    						<span class="post-date"><?php the_date(); /* echo get_the_date() に書き換える(CHAPTER 9) */ ?></span>
    						<span class="category">Category - <?php the_category( ', ' ) ; ?></span>
    						<span class="comment-num"><?php comments_popup_link( 'Comment : 0', 'Comment : 1', 'Comments : %' ); ?></span>
    					</p>
    
    					<?php the_excerpt();?>
    					<p class="more-link">
    						<a href="<?php the_permalink(); ?>"
    						title="「<?php the_title(); ?>」の続きを読む">続きを読む »</a>
    					</p>
    				</div>
    				<p class="thumbnail-box">
    					<?php if(has_post_thumbnail()) :
    						the_post_thumbnail("thumbnail");
    					else:
    					?>
    						<img src="<?php echo get_template_directory_url(); ?>/images/noimage.gif" alt="aaa" />
    					<?php
    					endif;
    					?>
    				</p>
    
    			</div>
    
    		<?php endwhile; // 繰り返し処理終了
    	else : // ここから記事が見つからなかった場合の処理 ?>
    			<div class="post">
    				<h2>記事はありません</h2>
    				<p>お探しの記事は見つかりませんでした。</p>
    			</div>
    	<?php endif;?>
    
    	<?php if ( $wp_query->max_num_pages > 1 ) : // ここからページャー ?>
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link( '« PREV' ); ?></div>
    			<div class="alignright"><?php previous_posts_link( 'NEXT »' ); ?></div>
    		</div>
    	<?php endif; // ページャーここまで ?>
    
    </div><!-- /main -->
    <!-- / index.php -->
    <?php get_sidebar();
    get_footer(); ?>

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック投稿者 erenae

    (@erenae)

    自力で解決することができました。

    画像をまでの位置を呼び出すget_template_directory_uri()
    get_template_directory_url()と間違って記述していたのが原因でした。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「ページャーが表示されない」には新たに返信することはできません。