• Hi @hwk-fr

    Say, I’ve setup a CPT with ACF Extended called “Products”

    The single posts in this CPT are at e.g. example.com/products/bosch-dishwasher/

    Under Admin for a CPT I toggle Yes to Archive Page in order to setup a parent page that I have full control over — like I would a regular “Page”

    The archive page has the URL example.com/products/

    How do I add the Gutenberg editor to this overview-type archive page? It already has the Show in rest set to yes, but I can’t find any custom fields that does the trick.

    Reason is, to be able to add blocks to this page I otherwise want to sculpt as I see fit, and not have it be a standard category-list type.

    Thank you very much.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter anthonybarro

    (@anthonybarro)

    Would still like to know.

    Thread Starter anthonybarro

    (@anthonybarro)

    2 months and no reply?

    Has this project been abandoned?

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    It is the holiday season, so I’m taking some fresh air ??

    Unfortunately Gutenberg is only available in Posts/Pages with an actual Content Editor. This is why it is impossible to use it on an ACF Options Page (which is also the Post Type Archive page), User Page, Term Page, Settings Page etc…

    You can try to submit the feature request to the WP Core Gutenberg team.

    Hope it helps!

    Have a nice day!

    Regards.

    To get around this, I made a private custom post type called Global Blocks. I create my custom “archive” then I get the blocks from that ID in a conditional for the CPT archive. I use a shortcode to do this, so in the conditional I just call that.

    add_shortcode( 'global-block', 'global_blocks_shortcode' );
    /** 
     * Global Blocks Shortcode
     * [global-block id="1234"]
     */
    function global_blocks_shortcode( $atts ) {
    
    	$output = $class = '';
    	
    	global $post;
    	
    	$atts = shortcode_atts( array( 
    		'id'    => '',
    	), $atts );
    	
    	$id = $atts['id'];
    	
    	if ( get_post_status( $id ) )  // check if ID exists
    	
    	if( $id ) : /////////////////////// check if ID is on the shortcode
    		
    	$content = get_post( $id ); 
    
    	if ( has_blocks( $content->post_content ) ) :
        $blocks = parse_blocks( $content->post_content );
        foreach( $blocks as $block ) :
            $output .= do_shortcode( render_block( $block ) );
        endforeach;
    	endif; 
    					
    	$status = get_post_status( $id );
    	
    		//don't output draft mode
    		if ( $status != 'publish' ) :
    			$output = '';
    		endif;
    		
    	endif; //if $id; /////////////////
    	
    	return $output; 
    		
    }
    

    You can create a page, which is then editable with Gutenberg, and show its content on your archive page.
    In your case: create a new page with the name Products, so that it has the permalink “/products/”. Then add an archive.php that looks something like this:

    <?php
    function custom_post_type_content(): string | false
    {
        $custom_post_types = get_post_types(['public' => true, '_builtin' => false], "names");
        $type = get_post_type();
        if (isset($custom_post_types[$type])) {
            // Get the static page with a matching slug
            $category_static_page = get_page_by_path($type);
    
            // If such a page exists, get it
            if (isset($category_static_page)) {
                // Output page content and apply the usual the_content filters
                return apply_filters('the_content', $category_static_page->post_content);
            }
        }
        return false;
    }
    
    if ($content = custom_post_type_content()) {
        get_header();
        echo $content;
        get_footer();
    } else {
        if (wp_redirect(home_url())) {
            exit;
        }
    }
    
    • This reply was modified 1 year, 11 months ago by Tim.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘“Archive page” with Gutenberg editor’ is closed to new replies.