サポート » テーマ » Twentyten の archive.php で月別表示されない

  • サイドバーで<?php wp_get_archives(‘type=monthly&cat=1’); ?>を使い月別一覧を表示させarchive.phpをテンプレートにして月別に記事を出力させようとしているのですが、
    URLは /?m=201208 /?m=201209 /?m=201210 と変化しているものの、
    肝心の記事は月別でなく全件表示されてしまっており困っております。

    テンプレートは、Twentytenです。

    http://sontaku.com/?cat=1

    原因が、お分かりになるようでしたら教えていただけますと有り難いです。

6件の返信を表示中 - 1 - 6件目 (全6件中)
  • モデレーター jim912

    (@jim912)

    giga.oikawaさん

    テンプレートは、Twentytenです。

    とのことですが、リンク先を見る限り、Twentyten そのままではないようです。
    この点に関して、どのようにしているのかもう少し情報の提供をお願いいたします。

    トピック投稿者 giga.oikawa

    (@gigaoikawa)

    jim912さま

    ご回答ありがとうございます。

    すみません。補足説明させて頂きます。今回は自分でつくったカスタムテンプレートの中にTwentytenのタグを組み込む形となっています。

    今回起点ファイルとなっているcategory-1.php にモジュールで組み込んだsidebar-blog.php内に設置した月別アーカイブリスト wp_get_archives(‘type=monthly&cat=1’)から表示されるarchive.phpでの表示が、月別記事が表示されずに、全件が表示されてしまうという症状です。

    下記が、archive.php とloop.phpの中身です。
    長々となりますしお手数ではありますが、中身をチェック頂けると助かります。

    [archive.php]

    <?php get_header(blog); ?>
    
    <div class="main_blog" role="main">
    <div class="main_img_blog">
    <img src="<?php bloginfo('template_directory');?>/images/blog_img/blog_header_img.jpg">
    </div>
    <!--left-->
    <div class="main_left_blog" >
    <div class="blog_block">
    <div class="post_t"><img src="<?php bloginfo('template_directory');?>/images/blog_img/post_t.jpg"></div>
    
    <?php
    	/* Queue the first post, that way we know
    	 * what date we're dealing with (if that is the case).
    	 *
    	 * We reset this later so we can run the loop
    	 * properly with a call to rewind_posts().
    	 */
    	if ( have_posts() )
    		the_post();
    ?>
    
    			<!---<h1 class="page-title">
    <?php if ( is_day() ) : ?>
    				<?php printf( __( 'Daily Archives: <span>%s</span>', 'twentyten' ), get_the_date() ); ?>
    <?php elseif ( is_month() ) : ?>
    				<?php printf( __( 'Monthly Archives: <span>%s</span>', 'twentyten' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'twentyten' ) ) ); ?>
    <?php elseif ( is_year() ) : ?>
    				<?php printf( __( 'Yearly Archives: <span>%s</span>', 'twentyten' ), get_the_date( _x( 'Y', 'yearly archives date format', 'twentyten' ) ) ); ?>
    <?php else : ?>
    				<?php _e( 'Blog Archives', 'twentyten' ); ?>
    <?php endif; ?>
    			</h1>-->
    
    <?php
    	/* Since we called the_post() above, we need to
    	 * rewind the loop back to the beginning that way
    	 * we can run the loop properly, in full.
    	 */
    	rewind_posts();
    
    	/* Run the loop for the archives page to output the posts.
    	 * If you want to overload this in a child theme then include a file
    	 * called loop-archive.php and that will be used instead.
    	 */
    	 get_template_part( 'loop', 'archive' );
    ?>
    </div>
    </div><!--leftここまで-->	
    
    <?php get_sidebar(blog); ?>
    
    <div class="pagenavi">
    <p class="page_top"><a href="#pagetop"><img src="<?php bloginfo('template_directory');?>/images/blog_img/m_pagetop.jpg"></a></p>
    <div class="pagenavi1">
    <?php posts_nav_link(' ','<img src="http://sontaku.com/wp-content/themes/sontaku/images/blog_img/previous_btn.jpg" />', ' '); ?></div>
    <div class="pagenavi2"><?php posts_nav_link(' ',' ','<img src="http://sontaku.com/wp-content/themes/sontaku/images/blog_img/next_btn.jpg" />'); ?></div>
    
    <div class="wp-pagenavi"><?php wp_pagenavi();?></div>
    </div>
    
    </div><!--main_blog-->
    
    <?php get_footer(blog); ?>

    [loop.php]※今回は”標準フォーマット”での投稿記事作成

    <?php
    /**
     * The loop that displays posts.
     *
     * The loop displays the posts and the post content. See
     * http://codex.wordpress.org/The_Loop to understand it and
     * http://codex.wordpress.org/Template_Tags to understand
     * the tags used in it.
     *
     * This can be overridden in child themes with loop.php or
     * loop-template.php, where 'template' is the loop context
     * requested by a template. For example, loop-index.php would
     * be used if it exists and we ask for the loop with:
     * <code>get_template_part( 'loop', 'index' );</code>
     *
     * @package WordPress
     * @subpackage Twenty_Ten
     * @since Twenty Ten 1.0
     */
    ?>
    
    <?php /* Display navigation to next/previous pages when applicable */ ?>
    <?php
    $paged = get_query_var('paged');
    query_posts("posts_per_page=5&paged=$paged");?>
    
    <?php /* If there are no posts to display, such as an empty archive page */ ?>
    <?php if ( ! have_posts() ) : ?>
    	<div id="post-0" class="post error404 not-found">
    		<h1 class="entry-title"><?php _e( 'Not Found', 'twentyten' ); ?></h1>
    		<div class="entry-content">
    			<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyten' ); ?></p>
    			<?php get_search_form(); ?>
    		</div><!-- .entry-content -->
    	</div><!-- #post-0 -->
    <?php endif; ?>
    
    <?php
    	/* Start the Loop.
    	 *
    	 * In Twenty Ten we use the same loop in multiple contexts.
    	 * It is broken into three main parts: when we're displaying
    	 * posts that are in the gallery category, when we're displaying
    	 * posts in the asides category, and finally all other posts.
    	 *
    	 * Additionally, we sometimes check for whether we are on an
    	 * archive page, a search page, etc., allowing for small differences
    	 * in the loop on each template without actually duplicating
    	 * the rest of the loop that is shared.
    	 *
    	 * Without further ado, the loop:
    	 */ ?>
    <?php while ( have_posts() ) : the_post(); ?>
    
    <!--Galleryでの表示-->
    <?php /* How to display posts of the Gallery format. The gallery category is the old way. */ ?>
    
    	<?php if ( ( function_exists( 'get_post_format' ) && 'gallery' == get_post_format( $post->ID ) ) || in_category( _x( 'gallery', 'gallery category slug', 'twentyten' ) ) ) : ?>
    		<div class="blog_date"><?php the_time('d/m/Y','','.') ?></div>
            <div class="blog_t"><?php the_title();?></div>
            <div class="blog_sabt"><?php the_excerpt();?></div>
            <div class="entry-content">
    <?php if ( post_password_required() ) : ?>
    				<?php the_content(); ?>
    <?php else : ?>
    				<?php
    					$images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
    					if ( $images ) :
    						$total_images = count( $images );
    						$image = array_shift( $images );
    						$image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail' );
    				?>
    						<div class="gallery-thumb">
    							<a>"><?php echo $image_img_tag; ?></a>
    						</div><!-- .gallery-thumb -->
    						<p><em><?php printf( _n( 'This gallery contains <a>%2$s photo</a>.', 'This gallery contains <a>%2$s photos</a>.', $total_images, 'twentyten' ),
    								'href="' . get_permalink() . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark"',
    								number_format_i18n( $total_images )
    							); ?></em></p>
    				<?php endif; ?>
    						<?php the_excerpt(); ?>
    <?php endif; ?>
    </div>
    
    <!--asideでの表示-->
    <?php /* How to display posts of the Aside format. The asides category is the old way. */ ?>
    
    	<?php elseif ( ( function_exists( 'get_post_format' ) && 'aside' == get_post_format( $post->ID ) ) || in_category( _x( 'asides', 'asides category slug', 'twentyten' ) )  ) : ?>
    		<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    		<?php if ( is_archive() || is_search() ) : // Display excerpts for archives and search. ?>
    			<div class="entry-summary">
    				<?php the_excerpt(); ?>
    			</div><!-- .entry-summary -->
    		<?php else : ?>
    			<div class="entry-content">
    				<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyten' ) ); ?>
    			</div><!-- .entry-content -->
    		<?php endif; ?>
    
    			<div class="entry-utility">
    				<?php twentyten_posted_on(); ?>
    				<span class="meta-sep">|</span>
    				<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
    				<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
    			</div><!-- .entry-utility -->
    		</div><!-- #post-## -->
    
    <?php /* How to display all other posts. */ ?>
    
    	<?php else : ?>
    
        <!--一般の表示-->
    
            <div class="blog_date"><?php the_time('m/d/Y','','.') ?></div><!--日付-->
    		<div class="blog_t"><a>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></div><!--タイトル-->
    		<?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
    			<!--<div class="blog_sabt"><?php the_excerpt();?></div>--><!--抜粋-->
                <div class="blog_content">
    				<?php the_content(); ?>
                    </div><!-- .entry-content -->
                    </div>
    	<?php else : ?>
    			<div class="blog_content">
    				<?php the_content(); ?>
                    </div><!-- .entry-content -->
    				<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    
    	<?php endif; ?>
    
    	<?php endif; // This was the if statement that broke the loop into three parts based on categories. ?>
    
    <?php endwhile; // End the loop. Whew. ?>
    
    <?php /* Display navigation to next/previous pages when applicable */ ?>
    <?php if (  $wp_query->max_num_pages > 1 ) : ?>
    				<div id="nav-below" class="navigation">
    					<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyten' ) ); ?></div>
    					<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div>
    				</div><!-- #nav-below -->
    <?php endif; ?>

    宜しくお願いいたします。

    モデレーター jim912

    (@jim912)

    giga.oikawaさん

    loop.phpのquery_postsが原因だと思います。

    トピック投稿者 giga.oikawa

    (@gigaoikawa)

    jim912さま

    ありがとうございます。

    ただ、下記のquery_postsを非表示にしたりget_postsに変えたり、やってみたのですが改善できません。

    <?php
    $paged = get_query_var(‘paged’);
    query_posts(“posts_per_page=5&paged=$paged”);?>

    最適な記述がわかれば幸いです。

    トピック投稿者 giga.oikawa

    (@gigaoikawa)

    jim912さま

    sontaku.com/?cat=1の月別一覧 wp_get_archives(‘type=monthly&cat=1’);
    を表示させるテンプレートをdate.phpとし、date.php内を下記の内容に一新してみましたが、依然、月別に表示されずに全件表示されてしまいます。

    やはり、ループの記述が間違っているのでしょうか?

    <?php get_header(blog); ?>
    
    <div class="main_blog" role="main">
    <div class="main_img_blog">
    <img src="<?php bloginfo('template_directory');?>/images/blog_img/blog_header_img.jpg">
    </div>
    <!--left-->
    <div class="main_left_blog" >
    <div class="blog_block">
    <div class="post_t"><img src="<?php bloginfo('template_directory');?>/images/blog_img/post_t.jpg"></div>
    <strong><?php $posts=get_posts('numberposts=5&category=1'); ?>
                        <?php if ($posts):
    					foreach($posts as $post):
    					setup_postdata($post); ?></strong>
    <div class="blog_date"><?php the_time('m/d/Y','','.') ?></div>
    <div class="blog_t"><a>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title();?></a></div>
    <!--<div class="blog_sabt"><?php the_excerpt();?></div>-->
    <div class="blog_content"><?php the_content();?></div>
    <strong><?php endforeach; endif; ?></strong>
    
    </div>			
    
    	</div><!--leftここまで-->		
    
    <?php get_sidebar(blog); ?>
    
    <!--<p class="navi_line"><img src="<?php bloginfo('template_directory');?>/images/blog_img/blog_foot_line.jpg"></p>-->
    
    <div class="pagenavi">
    <p class="page_top"><a>/?cat=1#pagetop"><img src="<?php bloginfo('template_directory');?>/images/blog_img/m_pagetop.jpg"></a></p>
    <div class="pagenavi1">
    <?php posts_nav_link(' ','<img src="http://sontaku.com/wp-content/themes/sontaku/images/blog_img/previous_btn.jpg" />', ' '); ?></div>
    <div class="pagenavi2"><?php posts_nav_link(' ',' ','<img src="http://sontaku.com/wp-content/themes/sontaku/images/blog_img/next_btn.jpg" />'); ?></div>
    
    <div class="wp-pagenavi"><?php wp_pagenavi();?></div>
    </div>
    <!--<p class="navi_line"><img src="<?php bloginfo('template_directory');?>/images/blog_img/blog_foot_line.jpg"></p>-->
    </div><!--main_blog-->
    
    <?php get_footer(blog); ?>
    トピック投稿者 giga.oikawa

    (@gigaoikawa)

    以下を使うことで自己解決しました。

    query_posts($query_string.’&cat=1&showposts=5′);

    お手数をおかけいたしました。

    しかし、なぜ$query_string.を使うことで改善できたのか?
    根拠は、いまだ未明です。。。

6件の返信を表示中 - 1 - 6件目 (全6件中)
  • トピック「Twentyten の archive.php で月別表示されない」には新たに返信することはできません。