Site logo

[Resolved] How to Create Custom Category (Archive) Pages

Home Forums Support [Resolved] How to Create Custom Category (Archive) Pages

Home Forums Support How to Create Custom Category (Archive) Pages

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #2474676
    Michael

    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

    #2474693
    Michael

    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

    #2475066
    Ying
    Staff
    Customer Support

    Hi Michael,

    You can use a block element - loop template to build custom archive pages, it will be like building a static page.

    For more info:
    https://docs.generatepress.com/article/block-element-loop-template/

    #2475119
    Michael

    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.

    #2475235
    Fernando
    Customer Support

    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

    #2475648
    Michael

    Thank you Fernando.

    #2476302
    Fernando
    Customer Support

    You’re welcome, Michael!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.