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

  1. pappyy
    Posted 2 years 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' );
    				<div class="inside">
    					<?php the_content(); ?>
    	<?php endwhile; ?>


  2. Jose Castaneda
    Posted 2 years 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
    Posted 2 years 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
    Posted 2 years 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.

Topic Closed

This topic has been closed to new replies.

About this Topic