Files
VDI-Starter/views/blocks/page-children/page-children.php
2025-09-26 08:46:53 -05:00

54 lines
1.2 KiB
PHP

<?php
/**
* Page Children block
*
* @package BasicWP
*/
namespace BasicWP;
// Retrieve the current page ID and its children
$parentId = get_queried_object_id();
// Children: direct descendants only
$children = get_posts(
array(
'post_type' => 'page',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => array(
'menu_order' => 'ASC',
'title' => 'ASC',
),
'order' => 'ASC',
'post_parent' => $parentId,
'fields' => 'all',
'no_found_rows' => true,
)
);
// 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; ?>