Skip to content

Commit

Permalink
Bug #18, add comments to simple_menu shortcode [iet:7491556]
Browse files Browse the repository at this point in the history
* Part of 'Tricky Topics Guide' work.
  • Loading branch information
nfreear committed Dec 19, 2016
1 parent eb73714 commit cd9c959
Showing 1 changed file with 52 additions and 11 deletions.
63 changes: 52 additions & 11 deletions simple_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function shortcode_simplemenu( $attr ) {
'menu' => 'Main',
'sub' => NULL,
'content' => false,
'comments'=> false,
], $attr ) );

$menu_obj = wp_get_nav_menu_object( $menu ); //232 ); //'Help' ); //'Main' );
Expand All @@ -58,7 +59,7 @@ public function shortcode_simplemenu( $attr ) {
$classes = self::SHORTCODE . " menu-$menu sub-$sub";

if ($content) {
return $this->display_content( $sub_menu, $parent_id, $classes );
return $this->display_content( $sub_menu, $parent_id, $classes, $comments );
}
return $this->display_menu( $sub_menu, $parent_id, $classes );
}
Expand All @@ -80,27 +81,67 @@ protected function display_menu( $sub_menu, $menu_id, $classes ) {
}


protected function display_content( $sub_menu, $menu_id, $classes ) {
protected function display_content( $sub_menu, $menu_id, $classes, $show_comments = false ) {
ob_start();

/* ?><ul class="<?php echo $classes ?>" id="sm-menu-<?php echo $menu_id ?>">
<?php */ foreach ($sub_menu as $it): ?>
?><div class="<?php echo $classes ?>" id="sm-menu-<?php echo $menu_id ?>">
<?php foreach ($sub_menu as $it): ?>
<div id="menu-item-<?php echo $it->object_id ?>" class="<?php self::echo_classes( $it, true ) ?>"
data-post='<?php self::post_json( $it ) ?>'>
data-post='<?php self::post_json( $it ) ?>' data-uri='<?php echo $it->url ?>'>
<h2 class="item-title"><?php echo $it->title ?></h3>
<?php //$page = get_page($it->object_id);?>
<?php echo apply_filters('the_content', get_post_field( 'post_content', $it->object_id )); ?>
<?php //var_dump( $it ); exit; ?>
<?php echo apply_filters('the_content', get_post_field( 'post_content', $it->object_id )) ?>
<?php self::display_comments( $it->object_id, $show_comments ) ?>
</div>
<?php endforeach; /* ?>
</ul><?php */
<?php endforeach ?>
</div><?php

$this->end();

return ob_get_clean();
}


protected static function display_comments( $post_id = null, $show_comments = false ) {
//echo $show_comments .' '. comments_open() .' '. get_comments_number();
if ( ! $show_comments || ! comments_open( $post_id ) ) {
return;
}

?>
<a class="comments-btn btn btn-primary" role="button" data-toggle="collapse" data-parent="#sm-menu-Z" href="#comments-<?php echo $post_id ?>"
><i class="fa fa-comments"></i>Your thoughts!</a>
<div class="item-comments collapse" id="comments-<?php echo $post_id ?>">
<?php comment_form( [
'id_form' => 'commentform-' . $post_id,
'id_submit' => 'submit-' . $post_id,
'class_submit'=> 'submit btn btn-primary',
'title_reply' => '<i class="fa fa-comments"></i>Your thoughts!',
'label_submit'=> 'Submit',
], $post_id ) ?>
<?php if ( get_comments_number( $post_id ) ): ?>
<ol class="comment-list">
<?php
wp_list_comments( [
'style' => 'ol',
'short_ping' => true,
'avatar_size' => 56,
], get_comments([ 'post_id' => $post_id ]) );
?>
</ol><!-- .comment-list -->
<?php else: ?>
<p class="no-comments">No thoughts yet. Be the first!</p>
<?php endif; ?>
</div>

<?php
/*
<?php if ( ($comments || comments_open()) || get_comments_number() ) :
echo 'YYY';
comments_template();
endif; ?>*/
}


protected function end( $shortcode = NULL ) {
$shortcode = $shortcode ? $shortcode : get_class($this);
$shortcode = str_replace('\\', '-', $shortcode); // Handle PHP namespaces.
Expand All @@ -124,7 +165,7 @@ protected static function post_json( $menu_obj ) {
'type' => $menu_obj->object,
# 'post_type' => $menu_obj->post_type, # 'nav_menu_item'
'modified' => $menu_obj->post_modified_gmt,
'url' => $menu_obj->url,
#'url' => $menu_obj->url,
'author_id' => $menu_obj->post_author,
'author' => get_the_author_meta( 'nickname', $menu_obj->post_author ), #Deprecated: get_author_name(..)
]);
Expand Down

0 comments on commit cd9c959

Please sign in to comment.