phil
phil

Reputation: 21

Wordpress Visual Composer Sidebar

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.

I must add menu-item classes to the

  • Tag (for example menu-item-112 and so on).

    Here is the following code:

    <?php
    function sidenavi_func( $atts, $content = null ) {
      global $post;
    
      $walker = array();
      $complete = false;
    
      $the_post = $post;
    
      while(!$complete) {
        array_push($walker, $the_post->ID);
    
        if($the_post->post_parent == 0) {
          $complete = true;
        }
        else {
          $the_post = get_post($the_post->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->query(array('post_type' => 'page',
                                       'post_parent' => $pid,
                                       'orderby' => 'menu_order',
                                       'posts_per_page' => -1,
                                       'order' => 'ASC'));
    
      $content = '';
      if(count($pages)) {
        if($start) {
          $content = '<ul class="sidenav">';
          $the_post = get_post($walker[count($walker) - 1]);
          $pid = 
          $content.= '<li class="active"><a href="'.get_permalink($the_post->ID).'">'.$the_post->post_title.'</a></li><br />';
        }
        else {
          $content = '<ul>';
        }
    
        foreach($pages as $page) {
          $active = false;
          foreach($walker as $item) {
            if($item == $page->ID) $active = true;
          }
          $content.= '<li'.($active ? ' class="active"' : '').'><a href="'.get_permalink($page->ID).'">'.$page->post_title.'</a>';
          if($expand_all || $active) {
            $content.= recursive_side_navi($walker, $page->ID);
          }
          $content.= '</li>';
        }
        $content.= '</ul>';
      }
    
      return $content;
    }
    add_shortcode( 'sm_sidenavi', 'sidenavi_func' );
    
    vc_map( array(
       "name" => __("Sidebar Navigation"),
       "base" => "sm_sidenavi",
       "class" => "sidenavi",
       "category" => __('Content'),
       'admin_enqueue_js' => '',
       'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/style.css'),
       'show_settings_on_create' => false,
       'custom_markup ' => '<div style="float: left; color: #d2e3ff; border: 1px solid #669fff; padding: 14px;"><p style="color: #669fff; padding: 30px 0; text-align: center;">Sidebar Navigation</p></div>'
       )
    );
    ?>
    

    Upvotes: 2

    Views: 48

  • Answers (0)

    Related Questions