The the7 theme allows you to control archive layout by selecting a page in Theme options > Archive. The selected page must have any page builder Blog module with required configuration. Please refer to the documentation for more details. However, there is no option if you want to assign different archive templates for categories. Let’s say, News archive want a list layout and Event archive to want to display in masonry grid. This can be done using the filter the7_archive_page_template_id
.
add_filter('the7_archive_page_template_id', 'archive_template_for_categories',10, 1); function archive_template_for_categories( $page_id ) { if( is_category( '18' ) ) { $page_id = 2; } if ( is_category( '19' ) ) { $page_id = 196; } return $page_id; }
Please remember to replace category ID ( #18, #19 ) and page ID ( #2, #196 ) with yours. Using this approach you can also apply a different template for a year or month archive. Just use the appropriate conditional tag. Please read about Conditional tags in the WordPress Codex.
Hi and thanks, very interested in this article. but where to paste this code?. I need is to change the date template.
Hi,
The code should go in your child theme’s functions.php
https://guide.the7.io/user-guide/child-theme/
Thanks for your quick response! … but it doesn’t work for me to change the date template. I need to remove the masonry and put the images of equal size. What should i change?
Hi,
It should work, please submit a ticket here
https://support.dream-theme.com
Thank you very much for sharing and solving the problem that has been bothering me. Thank you!
Hello, I am trying to assign different archive templates for PORTFOLIO categories and i’m not able to figure out how, I think that I have to use “dt_portfolio_category” instead of “category” but I dont know how.
Any suggestions?
Thank you in advance