• Resolved megseoh

    (@megseoh)


    I would like to use my archive.php template to display all of my archives, including my category, tags, posts, and custom post type archives. Currently the correct titles are displaying at the top of the pages, but the loop always shows my most recent posts and doesn’t filter them by category or tag. My custom post type archive is also displaying my most recent posts (regular posts, not custom post types posts). I am working behind a firewall so can’t post a link to the page. Here are the contents of my archive.php:

    <?php get_header(); ?>
    
    <div id="site-hero">
    </div>
    
    <div id="site-content">
    	<div class="container-fluid">
    		<div class="row">
    			<nav id="breadcrumbs" class="col-xs-12">
    				<?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb(); } ?>
    			</nav>
    			<div class="col-xs-12 col-sm-9">
    
    				<?php if (is_category()) { ?>
    					<div class="content-title">
    						<h3><?php _e( 'Posts Categorized:', 'bonestheme' ); ?>
    							<?php single_cat_title(); ?></h3>
    						<div class="title-underline"></div>
    					</div>
    
    				<?php } elseif (is_tag()) { ?>
    					<div class="content-title">
    						<h3><?php _e( 'Posts Tagged:', 'bonestheme' ); ?>
    							<?php single_tag_title(); ?></h3>
    						<div class="title-underline"></div>
    					</div>
    
    				<?php } elseif (is_author()) {
    					global $post;
    					$author_id = $post->post_author;
    				?>
    					<div class="content-title">
    						<h3><?php _e( 'Posts By:', 'bonestheme' ); ?>
    							<?php the_author_meta('display_name', $author_id); ?></h3>
    						<div class="title-underline"></div>
    					</div>
    
    				<?php } elseif (is_day()) { ?>
    					<div class="content-title">
    						<h3><?php _e( 'Daily Archives:', 'bonestheme' ); ?>
    							<?php the_time('l, F j, Y'); ?></h3>
    						<div class="title-underline"></div>
    					</div>
    
    				<?php } elseif (is_month()) { ?>
    					<div class="content-title">
    						<h3><?php _e( 'Monthly Archives:', 'bonestheme' ); ?>
    							<?php the_time('F Y'); ?></h3>
    						<div class="title-underline"></div>
    					</div>
    
    				<?php } elseif (is_year()) { ?>
    					<div class="content-title">
    						<h3><?php _e( 'Yearly Archives:', 'bonestheme' ); ?>
    							<?php the_time('Y'); ?></h3>
    						<div class="title-underline"></div>
    					</div>
    
    				<?php } ?>
    
    				<div>
    					<?php if (have_posts()) : ?>
    						<?php while (have_posts()) : the_post(); ?>
    
    							<div class="post">
    
    								<?php the_post_thumbnail('thumbnail'); ?>
    								<?php the_time('F j, Y') ?> | By <?php the_author(); ?>
    								<h4><a href="<?php the_permalink() ?>">
    								<?php the_title(); ?></a></h4>
    								<!-- <?php the_excerpt(); ?> -->
    
    								<hr style="clear: both" />
    
    							</div>
    
    						<?php endwhile; ?>
    
    						<div class="pagination">
    							<?php fase_pagination(); ?>
    						</div>
    
    					<?php endif; ?>
    
    				</div>
    
    			</div>
    			<div class="col-xs-12 col-sm-3">
    				<?php get_sidebar('right'); ?>
    			</div>
    		</div>
    
    		<!-- /.navbar-collapse -->
    	</div>
    </div>
    
    <?php get_footer(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter megseoh

    (@megseoh)

    Have made some minor progress. Realized that my archive.php was working correctly for regular posts, just not for my news custom post type. Made a copy & archive.php & renamed it archive-news.php & now the news archive page is displaying correctly, but not the category or tag filtering for these posts. If I filter my news post type by a specific category/tag the correct title displays at the top of the page but no posts are displayed. Suggestions?

    Thread Starter megseoh

    (@megseoh)

    I found a solution in this post http://wordpress.stackexchange.com/questions/57439/displaying-category-archive-of-custom-post-types. I added the code below to my functions.php & it allows me to sort my news custom post type posts by category/tag. It mixes them in with my regular posts on the category/tag archives pages, but that works for my needs.

    function query_post_type($query) {
        $post_types = get_post_types();
    
        if ( is_category() || is_tag()) {
    
            $post_type = get_query_var('news');
    
            if ( $post_type ) {
                $post_type = $post_type;
            } else {
                $post_type = $post_types;
            }
    
            $query->set('post_type', $post_type);
    
            return $query;
        }
    }
    add_filter('pre_get_posts', 'query_post_type');
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Archive page isn't filtering content’ is closed to new replies.