$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>block editor - Loading template part programatically, inline styles missing|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

block editor - Loading template part programatically, inline styles missing

matteradmin12PV0评论
<?php
/**
 * Data provider for block patterns.
 *
 * @package Test
 */

namespace RomArt\DataProviders;

/**
 * BlockPatternsDataProvider class.
 */
class BlockPatternsDataProvider extends DataProviderBase {
    /**
     * Gets the page header block pattern.
     *
     * @return string
     */
    public static function get_page_header_block_pattern(): string {
        $header_pattern_posts = get_posts( [
            'name'       => 'header-pages',
            'post_type'  => 'wp_template_part',
            'numberposts'=> 1,
        ] );

        if ( empty( $header_pattern_posts ) ) {
            return '';
        }

        return do_blocks( get_post_field( 'post_content', $header_pattern_posts[0]->ID ) );
    }

    /**
     * Gets the footer block pattern.
     *
     * @return string
     */
    public static function get_footer_block_pattern(): string {
        $footer_pattern_post = get_posts( [
            'name'       => 'footer-pages',
            'post_type'  => 'wp_template_part',
            'numberposts'=> 1,
        ] );

        if ( empty( $footer_pattern_post ) ) {
            return '';
        }

        return do_blocks( get_post_field( 'post_content', $footer_pattern_post[0]->ID ) );
    }
}

This works fine and it returns template parts, but some styles are missing.

When I use these template parts in the block editor, for example to create a page template, all styles are there. But when I load them programatically like this, some are missing.

I noticed some differences in CSS classes, such as when the foooter is loaded in the page template (block editor), it has class wp-container-core-group-is-layout-15 and it looks good, but when I load it programatically, it has wp-container-core-group-is-layout-10 and looks different

Post a comment

comment list (0)

  1. No comments so far