38 lines
864 B
PHP
38 lines
864 B
PHP
<?php
|
|
/**
|
|
* Page Children block
|
|
*
|
|
* @package BasicWP
|
|
*/
|
|
|
|
namespace BasicWP;
|
|
|
|
// Retrieve the current page ID and its children
|
|
$currentPageId = get_the_ID();
|
|
$currentPageChildren = get_pages( array( 'child_of' => $currentPageId ) );
|
|
|
|
// Set classes
|
|
$classes = 'page-children';
|
|
|
|
// Set wrapper attributes
|
|
if ( ! $is_preview ) {
|
|
$wrapper = get_block_wrapper_attributes( array( 'class' => $classes ) );
|
|
} else {
|
|
$wrapper = 'class="' . $classes . '"';
|
|
}
|
|
?>
|
|
|
|
<?php if ( ! empty( $currentPageChildren ) ) : ?>
|
|
<section id="page-children" <?php echo wp_kses_post( $wrapper ); ?>>
|
|
<ul>
|
|
<?php foreach ( $currentPageChildren as $child ) : ?>
|
|
<li class="page-child">
|
|
<a href="<?php echo esc_url( get_permalink( $child->ID ) ); ?>">
|
|
<?php echo esc_html( $child->post_title ); ?>
|
|
</a>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</section>
|
|
<?php endif; ?>
|