I want to add some custom content to each category page. The custom content would be placed above the list of posts for that category.
In this thread:
https://generatepress.com/forums/topic/how-to-customize-category-archive-page-layouts/
I found this code:
add_action( 'generate_before_main_content', 'tu_add_content_above_posts', 0 );
function tu_add_content_above_posts() {
if ( is_category( 'category-name' ) ) : ?>
Your content
<?php endif;
}
So, what I did is i modified the archive.php file by adding this:
do_action( 'generate_archive_title' );
/*my edit*/
if ( is_category( 'cat-1' ) ) : ?>
<div>
<p>
Custom content for cat 1.
</p>
</div>
<?php endif;
if ( is_category( 'cat-2' ) ) : ?>
<div>
<p>
Custom content for cat 2.
</p>
</div>
<?php endif;
/*end my edit*/
This seems to work fine. However, I’d have to create a child theme in order to persist this across an theme update.
Is there a more efficient way to do this? One that would not require a child theme. And perhaps allow for a separate file for each category with it’s own custom HTML content?
Thanks,
Hernan