• hberger

    (@hberger)


    I have a page (category-news.php) that displays all posts from category 1 (news).
    In the left column i want to display a list with monthly archive, for this category.

    To display the month list, i use this code:
    <?php wp_get_archives('type=monthly'); ?>

    And for the posts, this loop:

    <?php if (have_posts()) : ?>
            <?php while (have_posts()) : the_post(); ?>
    
                    <div class="right">
    
                        <h2><?php echo the_title(); ?> (<?php echo the_date(); ?>)</h2><span class="edit"><?php edit_post_link('EDIT'); ?></span>
                        <h3>Posted by <?php echo the_author(); ?></h3>
                        <div class="entry"><?php the_content(); ?></div>
                    </div> <!-- right -->
    
            <?php endwhile; ?>
    
                <div class="navigation">
                    <div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
                    <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></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; ?>

    The problems
    1. The month list displays months when there is nothing written in this category, but in others.

    2. When clicking on a month, i get posts from all categories.
    Well, I figured I had to put this before the loop in archive.php:
    <?php query_posts('category_name=news'); ?>

    With that code, I get the correct category – but I see posts from all moths, even if I click on a specific moth and the url is ending with ?m=200911

    Anyone? Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • huggie

    (@huggie)

    Because wp_get_archives() can be used anywhere, not just inside the loop, it gets archive months for all posts.

    Thread Starter hberger

    (@hberger)

    I allready knew my method doesn’t work ??

    Are there any ways to accomplish what I need to get done?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Archive with monthly list for one category’ is closed to new replies.