• adamrobertson

    (@adamrobertson)


    I have an archive page that’s set up to display category specific posts. However, instead of showing only the posts from a given category on the category page, it’s showing all posts. For an example, see here.

    Here’s the code I’m using on my archive.php page. I know it’s improper use of the loop, but I’m not sure how to fix it. Thanks for the help.

    <?php get_header(); ?>
        <div id="content">
            <div id="inner-content" class="wrap clearfix">
                <h1 class="blogTitle" style="margin:10px 0 3px 0;">Blog Title</h1>
                    <nav class="blogNav" role="navigation">
                        <?php bones_blog_nav(); // Adjust using Menus in WordPress Admin ?>
                    </nav>
                    <div id="main" class="eightcol first clearfix" role="main">
                        <div class="catwhiteBg">
                            <?php if (is_category()) { ?>
                            <h1 class="catTitle">
                                <span><?php _e("", "bonestheme"); ?></span> <?php single_cat_title(); ?>
                            </h1>
                            <?php echo category_description( $category_id ); ?>
    
                            <?php } elseif (is_author()) { ?>
                                <div class="authorTop">
                                    <?php
                                    $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
                                    ?>
                                    <div class="author-pic"><?php echo get_avatar( $curauth->user_email, '80' ); ?></div>
                                    <div class="author-name"><span style="font-weight: 200; color: #575757;">POSTS BY:</span>
                                            <?php echo $curauth->first_name; ?> <?php echo $curauth->last_name; ?>
                                    </div>
                                    <div class="author-bio"><?php echo $curauth->description; ?></div>
                                    <a href="<?php echo $curauth->twitter; ?>" title="Twitter"><div class="author-twitter"><span>twitter</span></div></a>
                                </div>
    
                            <?php } elseif (is_day()) { ?>
                                <h1 class="archive-title h2">
                                    <span><?php _e("Daily Archives:", "bonestheme"); ?></span> <?php the_time('l, F j, Y'); ?>
                                </h1>
    
                            <?php } elseif (is_month()) { ?>
                                <h1 class="archive-title h2">
                                    <span><?php _e("Monthly Archives:", "bonestheme"); ?></span> <?php the_time('F Y'); ?>
                                </h1>
    
                            <?php } elseif (is_year()) { ?>
                                <h1 class="archive-title h2">
                                    <span><?php _e("Yearly Archives:", "bonestheme"); ?></span> <?php the_time('Y'); ?>
                                </h1>
                            <?php } ?>
                        </div>
    
                        <div class="psts">
                            <?php
                            global $wp_query;
    
                            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
                            if ( get_query_var('paged') ) {
    
                            $paged = get_query_var('paged');
    
                            } elseif ( get_query_var('page') ) {
    
                            $paged = get_query_var('page');
    
                            } else {
    
                            $paged = 1;
    
                            }
    
                            query_posts(array('posts_per_page' => '8','paged'=>$paged));
                            ?>
    
                            <?php
                            $count = 1;
    
                            while (have_posts()) : the_post(); ?>
    
                            <div class="sixcol small pst<?php if ((isset($count)) && ($count % 2 == 0 )) { echo ' last';} // same logic to add class of last to last item in row of two ?>" id="post-<?php the_ID(); ?>">
                                <article id="post-<?php the_ID(); ?>" role="article">
                                    <div class="thumb-wrapper mobile">
                                        <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php if(has_post_thumbnail()) { $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'post-thumb' ); echo '<img src="' . $image_src[0] . '" width="100%" class="post-thumb" />'; } ?></a>
    
                                        <header class="post-thumb-header">
                                            <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><h2 class="post-title"><?php the_title(); ?></h2></a>
                                        </header> <!-- end article header -->
                                        <p class="meta"><?php the_category(', '); ?></p>
                                    </div>
    
                                    <section class="mobile-content">
                                        <?php the_excerpt(); ?>
                                    </section>
                                </article> <!-- end article -->
                            </div>
    
                            <?php $count++; ?>
    
                            <?php endwhile; ?>
    
                            <nav class="wp-prev-next">
                                <?php echo rb_pagination(); ?>
                            </nav>
                        </div> <!-- end .psts -->
                    </div> <!-- end #main -->
    
                <?php get_sidebar(); // sidebar 1 ?>
    
            </div> <!-- end #inner-content -->
    
        </div> <!-- end #content -->
    
    <?php get_footer(); ?>
  • The topic ‘Category template is showing posts from all categories instead of spec’ is closed to new replies.