PHP code example of ralfhortt / wp-block
1. Go to this page and download the library: Download ralfhortt/wp-block library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ralfhortt / wp-block example snippets
use RalfHortt\WPBlock\Block;
class MyBlock extends Block {
protected $name = 'ralfhortt/myblock';
protected $attributes = [
'postType' => [
'type' => 'string',
'default' => '',
],
// …
];
protected function render($atts, $content): void
{
$query = new WP_Query([
'post_type' => $atts['postType'],
'showposts' => 5,
]);
if ( $query->have_posts()) {
while ( $query->have_posts() ) {
$query->the_post();
the_title();
}
}
wp_reset_query();
}
}
class MyOtherBlock extends Block {
protected string $name = 'ralfhortt/myotherblock';
protected string $title = 'My other Block';
protected string $blockJson = 'block.json';
// …
}