class-block.php
1 year ago
class-button-container.php
2 years ago
class-button.php
2 years ago
class-container.php
2 years ago
class-element.php
1 year ago
class-grid.php
2 years ago
class-headline.php
2 years ago
class-image.php
2 years ago
class-loop-item.php
1 year ago
class-looper.php
1 year ago
class-media.php
1 year ago
class-query-loop.php
3 years ago
class-query-no-results.php
1 year ago
class-query-page-numbers.php
1 year ago
class-query.php
1 year ago
class-shape.php
1 year ago
class-text.php
1 year ago
class-loop-item.php
61 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Handles the Element block. |
| 4 | * |
| 5 | * @package GenerateBlocks |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; // Exit if accessed directly. |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * The Element block. |
| 14 | */ |
| 15 | class GenerateBlocks_Block_Loop_Item extends GenerateBlocks_Block { |
| 16 | /** |
| 17 | * Keep track of all blocks of this type on the page. |
| 18 | * |
| 19 | * @var array $block_ids The current block id. |
| 20 | */ |
| 21 | protected static $block_ids = []; |
| 22 | |
| 23 | /** |
| 24 | * Render the Element block. |
| 25 | * |
| 26 | * @param array $attributes The block attributes. |
| 27 | * @param string $block_content The block content. |
| 28 | * @param object $block The block. |
| 29 | */ |
| 30 | public static function render_block( $attributes, $block_content, $block ) { |
| 31 | $query_type = $block->context['generateblocks/queryType'] ?? null; |
| 32 | |
| 33 | if ( GenerateBlocks_Block_Query::TYPE_WP_QUERY === $query_type ) { |
| 34 | $post_classes = get_post_class(); |
| 35 | |
| 36 | if ( class_exists( 'WP_HTML_Tag_Processor' ) ) { |
| 37 | $tags = new WP_HTML_Tag_Processor( $block_content ); |
| 38 | |
| 39 | if ( $tags->next_tag( $attributes['tagName'] ) ) { |
| 40 | $existing_classes = $tags->get_attribute( 'class' ); |
| 41 | $new_classes = $existing_classes . ' ' . implode( ' ', $post_classes ); |
| 42 | $tags->set_attribute( 'class', $new_classes ); |
| 43 | $block_content = $tags->get_updated_html(); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // Add styles to this block if needed. |
| 49 | $block_content = generateblocks_maybe_add_block_css( |
| 50 | $block_content, |
| 51 | [ |
| 52 | 'class_name' => __CLASS__, |
| 53 | 'attributes' => $attributes, |
| 54 | 'block_ids' => self::$block_ids, |
| 55 | ] |
| 56 | ); |
| 57 | |
| 58 | return $block_content; |
| 59 | } |
| 60 | } |
| 61 |