Support » Fixing WordPress » wp_get_archives displaying months with no posts
wp_get_archives displaying months with no posts
-
Greetings all. I am trying to create a list of months of archived posts in the category with id 12. I’ve tried to use wp_list_archives but it is showing months that do not have posts. Here is my current code:
<body> <div class="body1"> <div class="body2"> <div class="whole"> <div class="whole2"> <div class="navbar"> <?php $link = get_post_meta($post->ID,'link',true); $sublink = get_post_meta($post->ID,'link',true); include 'inc/nav.php'; ?> </div> <?php endwhile; else: endif; ?> <?php include 'inc/testimonials.php'; ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> </div> <div class="content"> <div class="content2"> <div class="sub_content"> <div class="sub_header"> <h2 class="name"><?php the_title(); ?></h2> </div> <?php $pimg = get_post_meta($post->ID,'page_img',true); if ($pimg != '') { ?> <img src="<?php bloginfo('template_directory'); ?>/images/<?php echo $pimg; ?>" alt="<?php the_title(); ?> Image" class="page_img" /> <?php } ?> <div class="page_content news_content"> <?php endwhile; else: endif; ?> <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); global $more;$more = 0; $wp_query->query('orderby=date&order=DESC&cat=12&paged='.$paged); //while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <?php if (have_posts()) : ?> <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?> <?php while (have_posts()) : the_post(); ?> <h4><?php the_title(); ?></h4> <small> <?php the_time('F jS, Y') ?> </small> <div class="entry"> <?php the_content('<br /><br />Read more »'); ?> </div> <?php endwhile; ?> <div class="navigation"> <div class="alignleft"> <?php next_posts_link('« Older Entries') ?> </div> <div class="alignright"> <?php previous_posts_link('Newer Entries »') ?> </div> </div> <?php else : ?> <h2 class="center">Not Found</h2> <p class="center">Sorry, but you are looking for something that isn't here.</p> <?php endif; ?> </div> </div> <?php //endwhile; ?><?php// $wp_query = null; $wp_query = $temp;?> <div class="sidebar"> <div class="newartists"> <p class="headline">Archives</p> <?php wp_get_archives('type=monthly&format=custom&before=&after='); ?></div> </div><div class="clear"></div> </div> </div> <div class="clear"></div> </div></div></div></div> <?php include 'inc/foot.php'; ?> </body>
This is in a custom template… I believe I am probably doing this wrong.. I have also tried to put the “wp_get_archives” within the query and it still does not only pull the one month that the only post is in.
It is pulling 3 months which I assume means that it is pulling the months of all the posts but when I click on the archive month it says “could not find post”.
THanks
- The topic ‘wp_get_archives displaying months with no posts’ is closed to new replies.