<?php

/**
 * Children as paragraph sidebar
 */
global $post;
if (!isset($children)) {
    // In theory section that includes the sidebar should be getting list of children before including it, but just in case...
    $children = bb_get_children($post);
}
$has_children = true;
$menu_items = $children;
if (empty($menu_items)) {
    // No children, get siblings
    $has_children = false;
    $menu_items = bb_get_children($post->post_parent);
}
$menu = '';
foreach ($menu_items as $item) {
    $menu .= '        <li>' . "\n";
    if (!$has_children || bb_has_children($item->ID)) {
        $menu .= '            <a href="' . get_permalink($item->ID) . '">' . $item->post_title . '</a><hr>' . "\n";
    } else {
        $menu .= '            <a href="#' . get_the_slug($item->ID) . '">' . $item->post_title . '</a><hr>' . "\n";
    }
    $menu .= '        </li>' . "\n";
}
?>
<div class="hide-for-medium row" data-sticky-container>
    <div class="sticky small-24 column" data-sticky data-sticky-on="small" data-anchor="row-content">
        <ul class="menu vertical" data-accordion-menu>
<?php

/**
 * Section for displaying children as paragraphs
 */
global $post;
$children = bb_get_children($post);
?>
<aside class="small-24 medium-5 large-5 column">
    <?php 
get_sidebar('children-as-paragraphs');
?>
</aside>
<div class="small-24 medium-19 large-19 column">
<?php 
foreach ($children as $child) {
    $id = $child->ID;
    $slug = get_the_slug($child->ID);
    $title = $child->post_title;
    $content = apply_filters('the_content', $child->post_content);
    $read_more_label = get_theme_mod(ns_ . 'read_more_label', __('Read more on this topic'), ns_);
    $read_more_link = bb_has_children($child->ID) ? '<p><a href="' . $slug . '">' . $read_more_label . '</a></p>' : '';
    ?>
    <article id="<?php 
    echo $slug;
    ?>
">
        <h2><?php 
    echo $title;
    ?>
</h2>