title: Wordpress Visual Composer Sidebar
body: <p>I have some problems. We must work on a page from another agency. They write something to show a Sidebar. The site uses Visual Composer. </p>
  
  <p>I must add menu-item classes to the <li> Tag (for example menu-item-112 and so on). </p>
  
  <p>Here is the following code: </p>
  
  <pre><code>&lt;?php
  function sidenavi_func( $atts, $content = null ) {
    global $post;
  
    $walker = array();
    $complete = false;
  
    $the_post = $post;
  
    while(!$complete) {
      array_push($walker, $the_post-&gt;ID);
  
      if($the_post-&gt;post_parent == 0) {
        $complete = true;
      }
      else {
        $the_post = get_post($the_post-&gt;post_parent);
      }
    }
  
    $content = recursive_side_navi($walker, $walker[count($walker) - 1], false, true);
  
    return $content;
  }
  function recursive_side_navi($walker, $pid, $expand_all = false, $start = false) {
    $wp_query = new WP_Query();
    $pages = $wp_query-&gt;query(array('post_type' =&gt; 'page',
                                     'post_parent' =&gt; $pid,
                                     'orderby' =&gt; 'menu_order',
                                     'posts_per_page' =&gt; -1,
                                     'order' =&gt; 'ASC'));
  
    $content = '';
    if(count($pages)) {
      if($start) {
        $content = '&lt;ul class="sidenav"&gt;';
        $the_post = get_post($walker[count($walker) - 1]);
        $pid = 
        $content.= '&lt;li class="active"&gt;&lt;a href="'.get_permalink($the_post-&gt;ID).'"&gt;'.$the_post-&gt;post_title.'&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;';
      }
      else {
        $content = '&lt;ul&gt;';
      }
  
      foreach($pages as $page) {
        $active = false;
        foreach($walker as $item) {
          if($item == $page-&gt;ID) $active = true;
        }
        $content.= '&lt;li'.($active ? ' class="active"' : '').'&gt;&lt;a href="'.get_permalink($page-&gt;ID).'"&gt;'.$page-&gt;post_title.'&lt;/a&gt;';
        if($expand_all || $active) {
          $content.= recursive_side_navi($walker, $page-&gt;ID);
        }
        $content.= '&lt;/li&gt;';
      }
      $content.= '&lt;/ul&gt;';
    }
  
    return $content;
  }
  add_shortcode( 'sm_sidenavi', 'sidenavi_func' );
  
  vc_map( array(
     "name" =&gt; __("Sidebar Navigation"),
     "base" =&gt; "sm_sidenavi",
     "class" =&gt; "sidenavi",
     "category" =&gt; __('Content'),
     'admin_enqueue_js' =&gt; '',
     'admin_enqueue_css' =&gt; array(get_template_directory_uri().'/vc_extend/style.css'),
     'show_settings_on_create' =&gt; false,
     'custom_markup ' =&gt; '&lt;div style="float: left; color: #d2e3ff; border: 1px solid #669fff; padding: 14px;"&gt;&lt;p style="color: #669fff; padding: 30px 0; text-align: center;"&gt;Sidebar Navigation&lt;/p&gt;&lt;/div&gt;'
     )
  );
  ?&gt;
  </code></pre>