I have a list of events, which I would like to filter by month, using button-style links. Installed the Better Exposed Filter module, but there is no "link" option. Did someone met "Filter by month" scenario in BackdropCMS so far?
Most helpful answers
I believe the functionality you want is to 'page by date'. This was part of the Date module for Drupal 7, but was overlooked when Date was merged into Backdrop core. There's an open issue (with PR) for adding this functionality back into Backdrop: https://github.com/backdrop/backdrop-issues/issues/2766
Comments
Hello @mazze,
Have you tried https://drupal.stackexchange.com/questions/261310/d8-views-contextual-filter-by-month-year-content-date-field? It would be great to see if this works in D8 and/or vanilla Views 7.x, and if we are behind in any feature that supports implementing something like this in Backdrop.
I think that this is not supported in Views/Date/core yet (I might be wrong though), and if my research is right, then this is the issue to follow: https://www.drupal.org/project/drupal/issues/2868014. That issue is still in "needs work", but I've come across articles that mention "Filter Granularity" (like https://www.drupal.org/forum/support/post-installation/2013-12-23/answered-filter-criteria-in-views) and also https://www.drupal.org/forum/support/post-installation/2012-12-16/how-to-show-only-current-month-content-in-a-view and https://www.drupal.org/forum/support/post-installation/2012-03-28/views-making-a-date-filter-by-month-only-returns-all
So it seems that this may require some further research and trial/error to implement. Please do report back if you manage to find a way.
I believe the functionality you want is to 'page by date'. This was part of the Date module for Drupal 7, but was overlooked when Date was merged into Backdrop core. There's an open issue (with PR) for adding this functionality back into Backdrop: https://github.com/backdrop/backdrop-issues/issues/2766
@klonos thank you for doing the research... at least the first link looks familiar:-)
@BWPanda yes, this could be an explanation, thank you
I tried with both
- Better Exposed Filter (does not provide the "show as link" option)
- Creating a filter block in Views (using context filter)
None them worked. The point is, I have several D7 sites (see screnshot) where I could take the settings from for the second solution)... so I assume these settings are correct.
What could be the simpler way to get this working for a current project? Adaptions on BEF, Date Field or a custom module? (sure, in the long term, all of them would be great;-)
@mazzech what you need is "aggregation". I created a quick demo view.
As I can't upload files here, I put it on one of my servers:
http://olga.indigofloat.at/download/testview.json
Import it into a testing instance and add the block "Test view block" to your default layout.
There's a stackexchange post which explains a bit, what you need:
https://drupal.stackexchange.com/questions/31523/how-to-get-a-count-of-n...
But playing with the demo view might also help.
Btw., no need for additional modules, views is just fine.
@mazze - I was curious if the "Creating a filter block in Views" really doesn't work in Backdrop, as I use a similar setup as shown in your screenshot on a Drupal 7 site. So, I've created a respective View with a contextual filter in Backdrop 1.16.2, and it works well with the following setup:
- Add a date field to the content type "Post", and create some content.
- Create a view for content of type "post" with one page and one block display.
- Show fields, e.g. Title and your custom date field.
- Page display, add a contextual filter for the date field:
- Display all results
- Override title: Archive %1
- Granularity: Month
- Block display, add a contextual filter for the same field but with different settings:
- Display a summary
- Sort order: Descending
- Sort by: Date
- Format: List
- Display record count with link
- Date format options > Custom format > Custom summary date format > F Y
- Granularity: Month
- Place the block on the views page, and browse by month.
What do you think about the approach, does it work for you?
Hi Olaf, it took some months to test this...;- Thank you, it works.
Last little detail... is there an option to control the month's link URL. The overview page has URL
- example.com/evt/filter
The filtered pages have URL
- example.com/event/2020-xx
Is there a way to controll the latter, eg. change to /evt/2020--xx. The "inherits path" option only works for the first click, the second shows /evt/2020--xx/2020--xx
Glad that it worked for you! To fix the URL, try it this way:
- Look for the path on your Views Page display.
- Change to the Block display, set Inherits path to No.
- Edit the Contextual filter of the Block display, look for the Base path field, and use the path of your Page display (see 1.) to define it.
@mazze - I was curious if the "Creating a filter block in Views" really doesn't work in Backdrop, as I use a similar setup as shown in your screenshot on a Drupal 7 site. So, I've created a respective View with a contextual filter in Backdrop 1.16.2, and it works well with the following setup:
What do you think about the approach, does it work for you?