MODULES
...
Siteglide Modules
Blog
Blog Archive
17min
browse by month and/or search blog posts between two dates introduction this article will show how to add a parameter to the main blog module "include" liquid tag to enable advanced filtering by "release date" how to include the archive navigation feature an explanation of the three main sub layouts available in in the default layout (1) search between two dates (2) browse by months (3) browse by months under year header how to give user feedback about search results adding the advanced search parameter the "archive" blog navigation features all depend on the advanced search feature in order to enable this dependency, you will need to add a parameter on the page where you initially included a blog module use adv search 'true' note the word true must be in single quotes in the starter site example below, the module is initially included on the blog page, so we will do it here we also switch to the default layout as this contains the updated examples to include the archive navigation feature firstly, you will need to provide the following liquid to include your archive layout {% include 'modules/siteglide blog/get/get blog archive' archive layout "default/archive" archive layout type "sidebar years and date search" %} in the default layout, this liquid would be placed inside the sidebar/wrapper liquid file, but this is optional parameters archive layout the layout parameter refers to the main layout folder followed by a path to the folder storing any archive layouts you are using in the example, an /archive folder is used archive layout type the type parameter refers to the name of the archive layout file in the default/archive/ folder we have 3 different optional types of archive layout you can choose by entering their names in the type parameter we will show the liquid tag for including each include browse by months {% include 'modules/siteglide blog/get/get blog archive' archive layout "default/archive" archive layout type "sidebar" %} include browse by months under years header {% include 'modules/siteglide blog/get/get blog archive' archive layout "default/archive" archive layout type "sidebar years" %} include search blog between two dates {% include 'modules/siteglide blog/get/get blog archive' archive layout "default/archive" archive layout type "sidebar years and date search" %} blog archive layouts the following examples will take you through the different options browse by month archive {% for month in blog archive months %} {{month start | date "%b %y" }} {% endfor %} in this example, we use the blog archive months object and loop over the array for each iteration, a link is outputted which has two range parameters range gte= an epoch format date for midnight on the beginning of the first day of the selected month range lt= the date above + 1 month we don't use `lte` because the date is the first valid date in the next month we want every date up until then browse by months, organised into years this layout does not just organise the months available under the relevant year headers, it also will skip any years without a blog post archive by years {% for year in blog archive years %} {{year start | date "%y"}} {% assign months by year = blog archive months | group by "year" %} {% for month in months by year\[year start] %} {{month start | date "%b" }} {% endfor %} {% endfor %} this example uses the same links as the previous one however, it also organises the links into the years in which they belong by first looping over the years in the blog archive years and then using the group by liquid filter and another loop to output the month links grouped under the current iteration's year learn more about this liquid at the pos docs group by filter https //documentation platformos com/api reference/liquid/platformos filters#group by for loop https //documentation platformos com/api reference/liquid/loops search blog posts between two dates in the default layout, this option also includes the previous "browse by months organised into years" option for convenience though the code can be simply removed if you prefer we have removed it in this article's example it also adds a form for directly manipulating the url parameters to find the exact dates the user is interested in search by date start date end date {% comment %} add your custom error message here it can be renamed by changing its name in the argument for the s blog date search function and in the definition below {% endcomment %} in this example a form is used to take user input the siteglide function automatically adds the dates to the url parameters in the correct format you can rewrite the error function to customise the way the form handles invalid dates entered a note about date entry inputs on different browsers different browsers may display the date input fields very differently 3rd party javascript plugins are available for making sure these display with your desired design custom layouts this is a relatively complex feature, so some understanding of liquid will be necessary to understand how to create a custom layout the best way to start would be to copy one of the default layouts and edit it to provide the changes you need any layouts included with the above liquid will get access to the blog archive years and blog archive months arrays, which contain detailed data about the years and months respectively which contain valid blog posts this can be used to generate dynamic buttons to the user so they can browse blog archive years {% for year in blog archive years %} {{year start}} {{year end}} {% endfor %} blog archive months {% for month in blog archive months %} {{month start}} {{month end}} {{month year}} {% endfor %} in order to filter the blog list by date, you need to refresh the page url with parameters in the unix epoch time https //www unixtimestamp com/index php format the following url parameters will cause results in the list to filter and more than one can be added range gt greater than this will filter for blog posts after the given date range gte greater than or equal to this will filter for blog posts on and after the given date range lt less than this will filter for blog posts before the given date range lte less than or equal to this will filter for blog posts on and before the given date for the above to work, remember to set the use adv search true parameter (see start of article)! the pos documentation website has some useful tips on how to use liquid to convert date formats and manipulate dates and times see the following useful filters, and browse the docs for more localize https //documentation platformos com/api reference/liquid/platformos filters#localize aliases l date https //documentation platformos com/api reference/liquid/platformos filters#localize aliases l add to time https //documentation platformos com/api reference/liquid/platformos filters#add to time feedback for the user in the examples, you may notice another url parameter is used range type the s blog date search siteglide function for filtering blog posts by user inputted dates adds the parameter range type="between" this would allow the following liquid on the list layout to identify that this search is between two dates {% if context params range type == "between" %} posts between {{context params range gt | date "%d %b %y"}} {{context params range gte | date "%d %b %y"}} and {{context params range lt | date "%d %b %y"}} {{context params range lte | date "%d %b %y"}} {% endif %} whereas, you could use another range type to indicate that different feedback should be given to the user e g the parameter month in this example changes the sentence structure from "posts between" to "posts from" to communicate the different kind of filtering that is now taking place {% if context params range type == "month" %} posts from {{context params range gt | date "%b %y"}} {{context params range gte | date "%b %y"}} {% endif %} note in both of these examples the gte and gt dates are both outputted this is because only one is expected to be available the layout is designed to accept either