Reputation: 157
I am a newbie in drupal.
How can i create a year listing of hyperlinks like this :
2012 2011 2009 2008
of blog posts published within any year and then link them to a page to diplay a teaser listing of blog posts within that year
I have views module installed and using contextual filters for year. I would like to use PHP code to get result set from view in the templates.php file and pass the results to my template.
Then I need to build some url alias for diplaying the particular template .eg. site_url/blog/2012 should display my template.
Please note : I already have a template for site_url/blog as the blog landing page template
Please tell me if thats feasible and how to do that?
Upvotes: 0
Views: 2318
Reputation: 1375
You can do it all with Views, no taxonomy is needed. I'm not sure if this functionality is introduced only after the previous answers.
Have a look at Drupal's "archive' view, which is provided with views, but disabled. Enable it and examine it thouroughly. You should be able to sort it out based on that example.
This is what I did:
You need two views displaying all your posts. A PAGE-view and a BLOCK view. Make sure they are displayed alongside each other,on the same page.
In the PAGE view, create a contextual filter, on CONTENT: CREATED YEAR. This itself will be enough to filter your posts on a year given in the URL
In the BLOCK view, create a contextual filter, on CONTENT: CREATED YEAR. Then, you can choose:
When the filter value is NOT available:
• Display all results for the specified field
• Provide default value
• Hide view
X Display a summary
Upvotes: 1
Reputation: 746
You can use the DATE module that provide also the calendar module and with views you can do whatever you want .
Upvotes: 1
Reputation: 857
By default, the Taxonomy module creates a teaser listing for all nodes associated with a term. So if you create a Blog Year vocabulary and attach it to the blog node type using a term reference field, Taxonomy will automatically create a paged display for all nodes that have the "2012" term, and for all nodes that have the "2011" term, etc. You can set up a custom path structure for these using the pathauto module, which you should be using anyway.
Then all you need to do is create a block that links to each term. The Taxonomy Block module will do that. Or you could create a view to output these taxonomy links in a block.
If you're going to use Views, you don't necessarily need to use Taxonomy at all. Each node stores at least two date fields, both a created date and an updated date. You can easily access this in Views. Create a view of teaser displays and add the Content: Created Year
contextual filter. Unfortunately, I don't know a good solution right now for displaying the years in Drupal 7 Views, so I'd probably write a module for that bit.
Upvotes: 1
Reputation: 13957
You can use Drupal's built in taxonomy module for this. Go to the taxonomy page by going to admin->structure->taxonomy
.
In there you can create a new vocabulary called Year where you can enter as many or as few years as you like.
Then in your blog post content type create a new field called year and link it to the vocabulary by selecting term reference as the type and following the instructions from there.
If you wanted you could build a module that adds new years to the vocabulary automatically but that's a whole different question.
To then show only posts with that year in you can build a view. Install the Views module and go to structure->views
and add a new view to show content of type Blog Post. You can then set a contextural filter in the advanced tab to show ones tagged with the year. Then you can expose the filter so the user can change the year and you should be set.
NOTE: The view needs to be a page rather than a block for this to work.
Upvotes: 0