Initial commit to github
This commit is contained in:
37
views/blocks/page-children/page-children.php
Normal file
37
views/blocks/page-children/page-children.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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; ?>
|
||||
Reference in New Issue
Block a user