Archive by year problem

Feed 6 posts, 4 voices

Avatar
10 posts

I’ve setup a new news page on a site I’m building, and wanting to have an “archive by year” section showing just links to the archived news stories by year rather than month…I’m using this code in a sidebar…

<?php $article = $this->find('news'); ?>
<?php $archives = $article->archive->archivesByYear(); ?>

<h1>Archives By Year:</h1>
<ul>
<?php foreach ($archives as $date): ?>
  <li><a href="<?php echo BASE_URL . $this->url .'/'. $date . URL_SUFFIX; ?>"><?php echo strftime('%Y', strtotime(strtr($date, '/', '-'))); ?></a></li>
<?php endforeach; ?>
</ul>

Which works – I get 4 nice links in a list…however, they all say 2009 and not 2006, 2007, 2008, 2009…is there something I’m missing? Or is it because I’ve just created them all now (in 2009) and then reset the created/published dates in frog and its confused it?

 
Avatar
31 posts

Yes, I’d leave the real dates as they are, I’d not conside this a bug.

 
Avatar
184 posts

mycooluk,

You can in fact edit the created and submitted dates manually. The metadata tab (next to the page title tab) has these date fields that you can override for your convenience.

Hope that helps.

 
Avatar
10 posts

Thanks bluefrog – I have already manually changed each story’s date…what I need to know is how to make the links show the relevant year, rather than all 4 saying 2009 (but linking to the correct page)…seems to me the system is ignoring my altered created/submitted dates and just displaying 2009 because thats when they were all created.

 
Avatar
1493 posts

@mycooluk – what date(s) did you change in the Metadata? You have the options of manually editing either or both the “created” and the “published” date. If you only changed the latter, that would explain it. The archive plugin is hard-coded to look for the “created_on” date.

So — either you need to hack the plugin code1 (not recommended :) or manually alter the “created” date in the metadata. Unless there is something else going on, of course!

1 In frog/plugins/archive/archive.php, line 124.

 
Avatar
10 posts

I set both published and created to the same dates in the past – i’ve even just double checked and tried resaving pages, but to no avail.

Guess I’ll have to hard-code the links, which isn’t ideal.

 
Avatar
1493 posts

I set both published and created to the same dates in the past … but to no avail.

Then something has gone wrong. What you describe works perfectly for me (the 2008 entry was made this way)! :-S