Support » Themes and Templates » Combining year and category with permalinks

  • hanheg

    (@hanheg)


    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    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

    <?php
      $current_category = get_query_var('cat');
      $year ='';
      if(isset($_GET['postyear'])){
        $year = '&year='.intval($_GET['postyear']);
      }
    ?>
    <?php query_posts('cat='.$current_category . $year); ?>
    <?php while ( have_posts() ) : the_post(); ?><!-- start of loop -->

    hanheg

    (@hanheg)

    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:
    /%year%/%monthnum%/%category%/%post_id%/

    but not
    /%year%/%monthnum%/%category%/%postname%/

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

    hanheg

    (@hanheg)

    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….

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Combining year and category with permalinks’ is closed to new replies.