Date archive layouts question

It’s possible to assign a layout to date archive and set day, month, year or time as condition, but how can I make a looper provider by date range and not by terms or post type. Probably by using the query builder or a query string. Any hint how?

And how to display the title of that archive? Using an addition to the functions.php as it works for category archives (that was kindly provided by your staff some time ago - see below), but does only give the title of the fist post of that specific month.

function display_page_title() { 
$page_title = get_the_title(get_option('page_for_posts', true));
	return $page_title; 
}
add_shortcode('page_title', 'display_page_title');

Hi @mircotripoczky,

Thanks for reaching out!

1.) On your first question, I suggest that you set the multiple conditions with And or OR clause. See the example below.

2.) You need to use the meta query using the Query String option, please check this article to build your query

3.) To display the archive title, please update your custom code to the code below.

function display_page_title() {
$page_title = get_the_archive_title();
	return $page_title;
}
add_shortcode('page_title', 'display_page_title');

Hope that helps.

Thank you.

Thanks @marc_a,

1 .) (with OR) and 3.) worked. Thanks.

2.) I’m still trying to figure out how to get the year and/or month and/or day of the currently displayed date archive into the query. year=2019&monthnum=6 works, but it’s not dynamic based on the current date archive.

best regards
Mirco

Sorry for replying to my own post, but couldn’t edit it anymore.

Finally I found a way after playing around with some of the “{{dc:” to figure out what they can do.

{{dc:url:segment}} returns the year because it’s the first segment of the url after the base url and {{dc:url:segment index="1"}}returns the month because it’s the second segment of the url after the base url.

So the WP Query has to be like this: year={{dc:url:segment}}&monthnum={{dc:url:segment index="1"}} to just show me the posts of the currently displayed monthly archive.

PS: A complete overview of all the “{{dc:” (don’t know how to call them) and what they do or return in detail would be very helpful for the future. Couldn’t find such overview yet at https://theme.co/docs/

best regards
Mirco

1 Like

Hi Mirco,

Glad that you are able to find the solution, and thank you for your valuable suggestion on the documentation.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.