Skip to content

Instantly share code, notes, and snippets.

@vovafeldman

vovafeldman/docs-sidebar.php Secret

Created Aug 6, 2017
Embed
What would you like to do?
<div class="wedocs-sidebar">
<?php
if ( is_archive() ) {
$post = freemius_wedocs_get_root_doc();
}
$ancestors = array();
$root = $parent = false;
if ( $post->post_parent ) {
$ancestors = get_post_ancestors( $post->ID );
$root = count( $ancestors ) - 1;
$parent = $ancestors[ $root ];
} else {
$parent = $post->ID;
}
$show_drafts = current_user_can( 'edit_others_pages' );
$walker = new WeDocs_Walker_Docs();
$children = wp_list_pages( array(
'title_li' => '',
'order' => 'menu_order',
'child_of' => $parent,
'echo' => false,
'post_type' => 'docs',
'walker' => $walker,
'post_status' => $show_drafts ? 'publish,draft' : 'publish',
) );
?>
<form role="search" method="post" class="search-form wedocs-search-form"
action="<?php echo esc_url( home_url( '/help/documentation/search/' ) ) ?>">
<div class="wedocs-search-input">
<input type="search" class="search-field"
placeholder="<?php _e( 'Search', 'freemius' ) ?>"
value="<?php echo get_search_query() ?>" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>"/>
<button type="submit" class="fa fa-search"></button>
</div>
</form>
<script type="text/javascript">
(function ($) {
$('.search-form.wedocs-search-form').on('submit', function () {
var search = $(this).find('input').val().toLowerCase().trim();
if ('' === search) {
return false;
}
$(this).attr('action', $(this).attr('action') + encodeURIComponent(search) + '/');
});
})(jQuery);
</script>
<?php if ( $children ) { ?>
<ul class="doc-nav-list">
<?php echo $children; ?>
</ul>
<?php } ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment