WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Whats the .php file called when a user clicks on a Monthly archive? (9 posts)

  1. egr102
    Member
    Posted 2 years ago #

    I currently have a list of archives based on a monthly basis. This is generated using:

    <?php wp_get_archives('type=monthly&limit=12'); ?>

    This generates a list of months. What template page does the visitor get directed to when they click on a month?

    How can I tweak my exisiting loop to just show that months posts. My current loop is:

    <?php get_header(); ?>
    
    <div id="main" role="main">
    
    <?php
    if (is_home()) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=-6&paged=$paged");
    }
    ?>
    
    <div class="inner">
    
     <h1><?php trim(wp_title("")); ?></h1>
    
     <?php include ('sidebartwo.php'); ?>
    
     <section class="main-wrap twocol news">
    
     	<?php if (have_posts()) : ?>
     		<?php while (have_posts()) : the_post(); ?>
    
     	<article class="box-style">
    
    	 	<time><?php the_time('M d') ?><span><?php the_time('Y') ?></span></time>
    
    	 	<h2><a href="<?php the_permalink()?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    
    	 	<?php the_content(''); ?>
    
     	</article>
    
    	<?php endwhile; ?> 		    				 	
    
     	<div class="next-prev-wrap">
    
     		<span class="next"><?php next_posts_link( 'Older posts', $post->max_num_pages ); ?></span>
     		<span class="prev"><?php previous_posts_link( 'Newer posts', $post->max_num_pages ); ?></span>
    
     	</div>
    
    </section>    	
    
    <?php endif; ?>
    
    </div> <!-- /inner -->
    
    </div> <!-- /main -->
    
    <?php get_footer(); ?>
  2. Pankaj Pandey
    Member
    Posted 2 years ago #

    archives.php, create this file or edit if that is there

  3. egr102
    Member
    Posted 2 years ago #

    Okay well i've done that but with the loop that I have all I get displayed is all posts, no matter what month. How do I display just the posts within each month?

  4. egr102
    Member
    Posted 2 years ago #

    Can anyone not lend their voice? I'm really struggling to get this to work.

    When I click on a month it goes to a page, with the correct url and page title (saying the correct month) but the results are wrong.

    Whats going on?

  5. deepbevel
    Member
    Posted 2 years ago #

    I'll take a stab at it,

    All archives including monthy, use archive.php. The exception being categories, which sometimes has its own template, as well as tags. Furthermore, even if these taxonomies have their own templates, they may reference the main index or loop to get their loop.

    there should be something like this code in your archive template already:

    <?php elseif ( is_month() ) : ?>
    								<?php printf( __( 'Monthly Archives: %s', 'cc' ), '<span>' . get_the_date( 'F Y' ) . '</span>' ); ?>

    if you click a date archive link and it's not opening a monthly archive, and you aren't using custom "get template part" redirects, which might interfere, you most likely don't have this, and you need to add it to your archives template, or make a monthly archives.php with a mod of the above code (get rid of the condition).

    If you make the custom monthly archives template, put the "if is_month get_template_part ("your-monthly-archives-template.php") condition in your defsault archives template (before the header) so it can redirect monthly archive posts accordingly.

  6. egr102
    Member
    Posted 2 years ago #

    Hey, thanks for giving some advice. Really appreciate it.

    I copied your code, where exactly do I put it in archive.php? I couldn't get it working.

    I have literally just been testing my loop and the problem is this bit of code in archive.php:

    <?php
    		if (is_archive()) {
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		query_posts("cat=-6&paged=$paged");
    		}
    		?>

    I remove it and the archives work but I need to somehow exclude category 6 from being displayed. Is excluding a category easier to do than above?

  7. egr102
    Member
    Posted 2 years ago #

    Ahh, found a fix.

    Found this article: http://perishablepress.com/press/2007/08/06/super-loop-exclude-specific-categories-and-display-any-number-of-posts/

    Substituted my loop with this one and all works find and dandy.

    Thanks for your help deepbevel

  8. deepbevel
    Member
    Posted 2 years ago #

    You're welcome.

  9. deepbevel
    Member
    Posted 2 years ago #

    Just to be clear, you want the default 2011 single.php, but without the "Bookmark the permalink" is that right? or have you made other changes to the default single.php template? I'm not familiar with 2011 so It could be hard to know.

    As for your changes, just copy and save the entire template code into a text file. When the theme updates, paste it back in. However, it's reccommended that you make a child theme. That way you can re do any and all customizations to all template files at once simply by reactivating the child theme after parent theme update.

Topic Closed

This topic has been closed to new replies.

About this Topic