admin管理员组

文章数量:1332353

I would like to have 3 editable columns (25, 50, 25) like you can insert in Gutenberg, per default in every new page. How can I do this? If I give the columns to page.php they are not editable.

I would like to have 3 editable columns (25, 50, 25) like you can insert in Gutenberg, per default in every new page. How can I do this? If I give the columns to page.php they are not editable.

Share Improve this question edited Dec 18, 2019 at 14:36 bueltge 17.1k7 gold badges62 silver badges97 bronze badges asked Dec 18, 2019 at 13:54 CheckpointCheckpoint 133 bronze badges 2
  • 1 I am not 100% sure if I understand you correctly, but is it templates you are looking for? developer.wordpress/block-editor/developers/block-api/… – kraftner Commented Dec 18, 2019 at 14:40
  • nearly; if i do array('core/columns') and 'page' i get the block with "choose layout" - how to say now "25/50/25" by program to be complete? – Checkpoint Commented Dec 18, 2019 at 16:25
Add a comment  | 

2 Answers 2

Reset to default 2

So first of all this is explained in detail in the documentation, just not exactly for this particular case.

To summarize:

  • You want to set a "block template" for the post type "page".
  • In this block template you want to have one columns block with 3 column blocks inside with widths of 25%, 50% and 25%

In code this looks like this:

function wpse_354875() {
    $post_type_object = get_post_type_object( 'page' );
    $post_type_object->template = [
        [
            'core/columns',
            [],
            [
                [
                    'core/column',
                    ['width'=>25],
                    []
                ],
                [
                    'core/column',
                    ['width'=>50],
                    []
                ],
                [
                    'core/column',
                    ['width'=>25],
                    []
                ],
            ]
        ],
    ];
}
add_action( 'init', 'wpse_354875' );

Once you are into the column you can add to the column array other blocks that you can identify. Below is another core/paragraph, but you could easily register your own block that grabs the title in an h1 tag (yourOwnBlocks/h1title in the below). I tried this with other block builder blocks and hooray that works too!! Thanks, Kraftner great tip.

                [ 'core/columns',
            [],
            [
                [
                    'core/column',
                    ['width'=>50],
                    [
                        ['core/paragraph',
                            [
                                'placeholder' => __( 'Add Description...', 'wp-rig' ),
                            ],
                        ],
                    ],
                ],
                [
                    'core/column',
                    ['width'=>50],
                    [
                        ['yourOwnBlocks/h1title'],
                    ]
                ],
            ],
        ],

本文标签: themesi would like to have 3 default columns editable in guttenberg