Combining year and category with permalinks (4 posts)

  1. hanheg
    Posted 5 years ago #

    If I combine year and category in a link it works fine without permalinks, like this: /wordpress/?year=2010&cat=7
    I get the correct listing of posts.

    But as soon as I turn permalinks on it is no longer working. It tried different combinations of /%year%/%category%/
    But it fails to work. I get ALL post in that category instead of only the posts for the category in only that year. And the year fails to show in the permalinks.

    I've been looking around for some time now but can't find any working example of permalink structures combining %category% and %year%
    Am I missing something really obvious? Or am I trying something impossible?

    Any help is much appreciated..... thanks

  2. keesiemeijer
    Posted 5 years ago #

    You can pass the year to a query posts. Use links like this: http://www.yoursite/category/news/?postyear=2007 and use this above the loop in your archive.php or category.php

      $current_category = get_query_var('cat');
      $year ='';
        $year = '&year='.intval($_GET['postyear']);
    <?php query_posts('cat='.$current_category . $year); ?>
    <?php while ( have_posts() ) : the_post(); ?><!-- start of loop -->
  3. hanheg
    Posted 5 years ago #

    Hi Keesie, thanks, but I know about that. The thing is that I need to build a link in the sidebar that combines years en category. That works fine as long as I don't use permalinks. But as soon as I use permalinks it fails.

    I did some further testing and this permalink setting seems to work:

    but not

    Of course, I would like to use the last one.
    Any more thoughts about this? Perhaps I have run into a bug?

  4. hanheg
    Posted 5 years ago #

    Hi Keesie,
    Just to let you know that I reverted to your solution in the end. Now I have the postname in the "neat url" and the year and month with questionmarks. That's better in the end.

    Thanks a lot for pointing this solution out. It helped me make the right choice....

Topic Closed

This topic has been closed to new replies.

About this Topic