WordPress.org

Ready to get started?Download WordPress

Forums

How do I show only one Category on an Archive page? (4 posts)

  1. pappyy
    Member
    Posted 7 months ago #

    Hi there. I'm editing my Archive.php page (Yes, got backups and child themes and everything, so don't worry about any of that) but I can't work out how to show only one Category (category 5, by the way)

    Here's my current code. Can anyone show me exactly how to make it so it only shows results from category 5?

    get_header(); ?>
    
    <?php /* The loop */ ?>
    
    <div class="left-column">
    
    	<?php while ( have_posts() ) : the_post(); ?>
    		<div class="social-main-content">
    			<h3 class="h3-title"><?php
    					if ( is_day() ) :
    						printf( __( 'Daily Archives: %s', 'twentythirteen' ), get_the_date() );
    					elseif ( is_month() ) :
    						printf( __( 'Monthly Archives: %s', 'twentythirteen' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'twentythirteen' ) ) );
    					elseif ( is_year() ) :
    						printf( __( 'Yearly Archives: %s', 'twentythirteen' ), get_the_date( _x( 'Y', 'yearly archives date format', 'twentythirteen' ) ) );
    					else :
    						_e( 'Archives', 'twentythirteen' );
    					endif;
    				?>
    			</h3>
    				<div class="inside">
    					<?php the_content(); ?>
    				</div>
    		</div>
    	<?php endwhile; ?>
    
    </div>

    Thanks!

  2. Jose Castaneda
    Member
    Posted 7 months ago #

    Why not just use a category-5.php file? If you take a quick look at how the template hierarchy works it helps. It took a little bit for me to understand it. :)

  3. pappyy
    Member
    Posted 7 months ago #

    That doesn't look like it will work.

    Because of the way I'm creating the site, I need it so that the user can ONLY see Catagory 5 in the Archive, no matter which date they're on.

    It needs to be auto generated too, so I can hand it over to my client and leave them with it. In February I don't want to have to go in and reedit a file, or anything like that.

  4. Jose Castaneda
    Member
    Posted 7 months ago #

    Why not just alter the query? Use a new WP_Query and set that up in the index file or wherever you have the main loop. Short of using, dare I say it, query_posts that's one way I can possibly think of.

Reply

You must log in to post.

About this Topic