Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wpf_documentation_sidebar() {
- ob_start();
- $category = get_query_var( 'documentation_category' );
- global $post;
- ?>
- <div id="categories-sidebar" class="sidebar line-top">
- <h3>In this chapter</h3>
- <?php $posts = get_posts( array('post_type' => 'documentation', 'documentation_category' => $category, 'fields' => 'ids', 'orderby' => 'title', 'order' =>'ASC', 'posts_per_page' => -1) ); ?>
- <ul class="category-posts">
- <?php foreach($posts as $id) : ?>
- <li><a <?php if($post->ID == $id) echo 'class="active" '; ?> href="<?php echo get_permalink( $id ) ?>" title="<?php echo get_the_title($id) ?>"><?php echo get_the_title( $id ); ?></a></li>
- <?php endforeach; ?>
- </ul>
- </div>
- <?
- return ob_get_clean();
- }
- add_shortcode( 'wpf_documentation_sidebar', 'wpf_documentation_sidebar' );
- function wpf_documentation_nav() {
- ob_start();
- global $post;
- $depth = 4;
- $pattern = '/<h[2-' . $depth . ']*[^>]*>.*?<\/h[2-' . $depth . ']>/';
- $whocares = preg_match_all( $pattern, $post->post_content, $winners );
- foreach ( $winners[0] as $i => $winner ) {
- $winners[0][ $i ] = str_replace( '<h4>', '<h4><a href="#' . sanitize_title( $winner ) . '">', $winners[0][ $i ] );
- $winners[0][ $i ] = str_replace( '</h4>', '</a></h4>', $winners[0][ $i ] );
- $winners[0][ $i ] = str_replace( '<h3>', '<h3><a href="#' . sanitize_title( $winner ) . '">', $winners[0][ $i ] );
- $winners[0][ $i ] = str_replace( '</h3>', '</a></h3>', $winners[0][ $i ] );
- }
- //reformat the results to be more usable
- $heads = implode( "\n", $winners[0] );
- $heads = preg_replace( '/<h([1-' . $depth . '])>/', '<li class="toc$1">', $heads );
- $heads = preg_replace( '/<\/h[1-' . $depth . ']>/', '</li>', $heads );
- ?>
- <div id="nav-sidebar" class="sidebar line-top">
- <h3>On this page</h3>
- <ul><?php echo $heads; ?></ul>
- </div>
- <?php
- return ob_get_clean();
- }
- add_shortcode( 'wpf_documentation_nav', 'wpf_documentation_nav' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement