0

Is it possible to generate a year-wise archive of blogs using views?I need years listed like 2001,2002,...2012 and clicking on the year should display list of blogs for that particular year. I added a contextual Filter Content: Created year also , but it this query only

SELECT DISTINCT node.nid AS nid, EXTRACT(YEAR FROM((DATE_ADD('19700101', INTERVAL node.created SECOND) + INTERVAL 0 SECOND))) AS created_year, COUNT(node.nid) AS num_records
FROM 
{node} node
WHERE (( (node.status = '1') AND (node.type IN  ('blog')) ))
GROUP BY created_year, nid
ORDER BY created_year ASC
.So this results in duplicate value for years

  • Try to remove “Distinct” flag in “Query options” – kalabro Jul 4 '12 at 8:25
2

Check “Archive” view from standard Views install for start.
In your case you need to use contextual filter “Content: Created year” instead of “Content: Created year + month”.

enter image description here

  • I did like that, but it displays query like this only <pre><code>SELECT DISTINCT node.nid AS nid, EXTRACT(YEAR FROM((DATE_ADD('19700101', INTERVAL node.created SECOND) + INTERVAL 0 SECOND))) AS created_year, COUNT(node.nid) AS num_records FROM {node} node WHERE (( (node.status = '1') AND (node.type IN ('blog')) )) GROUP BY created_year, nid ORDER BY created_year ASC</pre></code> and so it results in duplicate values – user7282 Jul 4 '12 at 8:11
  • @user7282, drupal.stackexchange.com/editing-help#comment-formatting. You can update your question to add more info about your problem. – kalabro Jul 4 '12 at 8:12
0

I am trying to help you out.I am not sure whether it will work for you or not. (Drupal 7) Go to your views, then go to advanced and go to query settings and check "distinct".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.