admin_url( 'admin-ajax.php' ), 'template_directory_uri' => get_template_directory_uri(), 'plugin_url' => ABSOLUTE_BLOCKS_URL, 'rest_api_url' => esc_url_raw( get_rest_url() ), ); wp_localize_script( 'absolutte_blocks-cgb-block-js', 'absolutte_blocks', $absolutte_blocks_custom_js ); // Styles. wp_enqueue_style( 'absolutte_blocks-cgb-block-editor-css', // Handle. plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS. array( 'wp-edit-blocks' ) // Dependency to include the CSS after it. // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: filemtime — Gets file modification time. ); } // End function absolutte_blocks_cgb_editor_assets(). // Hook: Editor assets. add_action( 'enqueue_block_editor_assets', 'absolutte_blocks_cgb_editor_assets' ); /** * Regsitering Dynamics Blocks * * */ function absolutte_blocks_register_dynamic_blocks() { if ( function_exists( 'register_block_type' ) ) { register_block_type( 'absolutte-blocks/blog', array( 'attributes' => array( 'title' => array( 'type' => 'array', 'source' => 'children', 'selector' => 'h3', 'items' => [ 'type' => 'string', ], ), 'idAttr' => array( 'type' => 'string', ), ), 'render_callback' => 'absolutte_blocks_dynamic_blog', ) ); } } add_action( 'init', 'absolutte_blocks_register_dynamic_blocks' ); /** * Dynamic Blog * */ function absolutte_blocks_dynamic_blog( $attributes, $content ) { $title = ''; if ( isset( $attributes['title'] ) ) { $title = $attributes['title'][0]; } $idAttr = ''; if ( isset( $attributes['idAttr'] ) ) { $idAttr = esc_attr( $attributes['idAttr'] ); } $second_post_html = ''; $args = array( 'posts_per_page' => 4, ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) {$the_query->the_post(); if ( $the_query->current_post == 0 ) { $main_post_html = sprintf( '
', esc_url( get_the_permalink() ), esc_html( get_the_title() ), esc_html( get_the_date() ), "'" . esc_url( get_the_post_thumbnail_url( get_the_ID(), 'large' ) ) . "'" ); } else { $second_post_html .= sprintf( '', esc_url( get_the_permalink() ), esc_html( get_the_title() ), esc_html( get_the_date() ), "'" . esc_url( get_the_post_thumbnail_url( get_the_ID(), 'large' ) ) . "'" ); } } //while } else { // if have posts $testimonials_html = '' . esc_html__( 'There are no testimonials to show', 'absolutte-blocks' ) . '
' . esc_html__( 'This block uses testimonials from Jetpack Plugin. You can enable testimonials on Jetpack > Settings > Custom content types', 'absolutte-blocks' ) . '