Site logo

Archived topic

How to Create Custom Category (Archive) Pages

6 replies · Started by Michael on December 27, 2022

Viewing posts 1–7 of 7

Hello - can you please provide a link to a tutorial on creating customized dynamic archive pages? I just want to create a grid at the top of the each archive page with some styling and then a container below that lists posts in a 2 or 3 column format. I've been playing with elements, query loops, etc. and just can't figure it out. (I have GP Premium).

Something like:

Container
Container/Grid -- Category Name
Container/Grid -- Category Desc
Container
Repeat
Container/Grid -- Post title, post excerpt
Container/Grid -- Post title, post excerpt
Container/Grid -- Post title, post excerpt

My indentations were clipped out:

Container
##### Container/Grid — Category Name
##### Container/Grid — Category Desc
Container
##### Repeat
##### Container/Grid — Post title, post excerpt
##### Container/Grid — Post title, post excerpt
##### Container/Grid — Post title, post excerpt

Thanks Ying - this got me 95% of the way there. The remaining challenge I have is displaying the description for the category. I use dynamic text to display the category name by choosing title, but I can't get the category description to display - I have tried using term meta and post meta as well as entering "Description" as the meta field name.

In summary, for my example category of "Holiday Posts" I am able to dynamically render the category title and loop/list all the posts that are assigned to the category, but I am unable to get the description for the category to dynamically display.

Thanks again for your help.

Hi Michael,

To do this, add a static GB Headline Block. Give it a text - placeholder

Give it a class of get-term-description

Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/

Then, add this PHP snippet:

add_filter( 'render_block', function( $block_content, $block ) {
    if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'get-term-description' ) !== false ) {
		$myreplace1 = 'placeholder';
		$myinsert1 = get_the_archive_description();
        $block_content = str_replace( $myreplace1, $myinsert1 , $block_content );
		
		
    }

    return $block_content;
}, 10, 2 );

Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

Thank you Fernando.

You're welcome, Michael!

This archived topic is closed to new replies.