• Hi –
    Have been trying tackle this all day, and have got frustratingly close. However, not close enough.

    I’m trying to make it so that when a date archive is viewed (for example “www.site.com/2008/10”), only posts from category ‘5’ are shown. Now, I’m aware that this can be done with permalinks and category archives (ie “www.mysite.com/work/2008/10”), however adding in date elements to the permalink would affect other sections of the site, and the client has specifically asked that they remain %category%/%postname%.

    So. I have my archive.php page set up with various Conditional tags (like if_category, if_tag etc) and using separate page templates depending on the archive type. I have added the following for the is_date function:

    elseif (is_date()) {
     	   	query_posts('cat=5');
    		include(TEMPLATEPATH . '/archive_date.php');
     	  } ?>

    When visiting a Date Archive, the correct template is being called, and all the posts are from the right category. However, the posts are not being limited by the date specified in the URL, and instead all the posts from the category are show, regardless of date posted… But here’s the strange thing:
    The archive only displays posts on months when posts exist, so it is still understanding the date query. For example, I have a post in September – using “www.mysite.com/blog/2008/09” shows a list of all my posts from the Blog category, the same as it does for this month (/2008/10), which also contains posts. But if I go to a month when I made no posts (for example, /2008/05), it returns no results.

    So WordPress is understanding that I am asking for archives for dates, and understands I am asking for only posts from one category. The only problem is that it is not limiting the output of posts, and just prints all of them.

    Any help would be much appreciated,
    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Restricting Date Archive to one category’ is closed to new replies.