<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-33304191</id><updated>2024-11-01T03:34:09.755-07:00</updated><category term="PHP"/><category term="Drupal"/><category term="WordPress"/><title type='text'>Helper Class</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://helperclass.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/33304191/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://helperclass.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-33304191.post-2939022638997093974</id><published>2012-06-18T07:06:00.001-07:00</published><updated>2012-06-18T07:08:28.544-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Drupal"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><title type='text'>Drupal 7 Webform with an item catalog table element</title><content type='html'>I was working on a Drupal 7 project and there was a requirement of a form with some simple text fields to put values and some elements in a grid like format to display catalog of items including item name, price, a text box for quantity and automatically calculated sub totals and grand total.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNl1F6ePtpL39tuDJdxrWL15zzYv6fKwR5HeZW88EQuVFQ-7E9T0TvPohsK3DoYHmsjRv6bkwCOanx5z_Z214U6WC2soYBN9-e87Yk37cbRHaa7qv0tM3FxoKXNLuoFRuoX0rN/s1600/Drupal_custom_webform_element.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNl1F6ePtpL39tuDJdxrWL15zzYv6fKwR5HeZW88EQuVFQ-7E9T0TvPohsK3DoYHmsjRv6bkwCOanx5z_Z214U6WC2soYBN9-e87Yk37cbRHaa7qv0tM3FxoKXNLuoFRuoX0rN/s1600/Drupal_custom_webform_element.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
I started with &lt;a href=&quot;http://drupal.org/project/webform&quot; target=&quot;_blank&quot;&gt;webform&lt;/a&gt; module but the built in grid element did not work. Then I tried &lt;a href=&quot;http://drupal.org/project/webform_table_element&quot; target=&quot;_blank&quot;&gt;webform_table_element module&lt;/a&gt;, it had some bugs but I managed to configure it. But, unfortunately, it was not able to produce a similar form. I was on a tight deadline (as usual) and did not have time to do something custom, so I decided to try some workaround and after spending a little time I got acceptable result.&lt;br /&gt;
&lt;br /&gt;
I am writing some simple steps to re-generate similar result.&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;I know this is not an ideal solution but it can save a little time if you have to add a couple of similar forms in your Drupal based project.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;i&gt;&lt;span style=&quot;background-color: white;&quot;&gt;You need to install &lt;a href=&quot;http://drupal.org/project/webform&quot; target=&quot;_blank&quot;&gt;webform&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;a href=&quot;http://drupal.org/project/webform_table_element&quot; target=&quot;_blank&quot;&gt;webform_table_element module&lt;/a&gt;&amp;nbsp;modules first.&lt;/span&gt;&lt;/i&gt;&lt;/blockquote&gt;
&lt;br /&gt;
a) Add a field of type &lt;i&gt;table_element&lt;/i&gt; in &lt;i&gt;webform&lt;/i&gt;. &lt;i&gt;table_element&lt;/i&gt; type requires you to put key|value pairs in &#39;Rows&#39; textarea there, convert your &#39;value&#39; to a simple JSON so it can be accessed later, something like:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:php&quot;&gt;1|{&quot;ID&quot;:&quot;001&quot;, &quot;title&quot;:&quot;My Item 1&quot;, &quot;rate&quot;:&quot;245&quot;}
2|{&quot;ID&quot;:&quot;002&quot;, &quot;title&quot;:&quot;My Item 2&quot;, &quot;rate&quot;:&quot;460&quot;}
3|{&quot;ID&quot;:&quot;003&quot;, &quot;title&quot;:&quot;My Item 3&quot;, &quot;rate&quot;:&quot;740&quot;}
&lt;/pre&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
And here is a screenshot:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBJDX3B5IA1M8il9H5BudPMrCRrif7DtKashNuw443gYXRsoH6a4k_JDMhWK4s9NxyN0_ZR3pFQKIvoIPzSOl9lvRNXF9xL6E9Ybdhj-Q63sWPz0g3W10ltHWlYsNdFSnslVSH/s1600/Drupal_step_1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBJDX3B5IA1M8il9H5BudPMrCRrif7DtKashNuw443gYXRsoH6a4k_JDMhWK4s9NxyN0_ZR3pFQKIvoIPzSOl9lvRNXF9xL6E9Ybdhj-Q63sWPz0g3W10ltHWlYsNdFSnslVSH/s1600/Drupal_step_1.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
b) Add these child elements under newly created &lt;i&gt;table_element &lt;/i&gt;type item:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkZqajhrCJyEOcJaXY-kdhXddF_nPb6tVUsea51P-OuxkgVrf3vw9NMtRt2wnnv9HDYNbcMa4BTmBuD_FVmd5Bj77_yCU8ahXslIWo8ixDLJyEjvWFLe0THGkFmEmuc4HqVkSP/s1600/Drupal_step_2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkZqajhrCJyEOcJaXY-kdhXddF_nPb6tVUsea51P-OuxkgVrf3vw9NMtRt2wnnv9HDYNbcMa4BTmBuD_FVmd5Bj77_yCU8ahXslIWo8ixDLJyEjvWFLe0THGkFmEmuc4HqVkSP/s1600/Drupal_step_2.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;Item Name&lt;/span&gt;&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Type: markup&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Label:&amp;nbsp;&lt;/span&gt;Item Name&lt;/li&gt;
&lt;li&gt;Field Key:&amp;nbsp;item_name&lt;/li&gt;
&lt;li&gt;Value: Name&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Item Rate&lt;/span&gt;&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Type: markup&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Label:&amp;nbsp;&lt;/span&gt;Item Rate&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Field Key:&amp;nbsp;&lt;/span&gt;item_rate&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Value: Rate&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Quantity&lt;/span&gt;&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Type: textfield&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Label:&amp;nbsp;&lt;/span&gt;Quantity&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Field Key:&amp;nbsp;&lt;/span&gt;quantity&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Item Rate&lt;/span&gt;&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Type: markup&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Label:&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;tabledrag-handle&quot; href=&quot;http://localhost:8080/ali/ADIBF/site/node/6/webform?render=overlay#&quot; title=&quot;Drag to re-order&quot;&gt;&lt;/a&gt;Sub Total&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Field Key:&amp;nbsp;&lt;/span&gt;sub_total&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Value:&amp;nbsp;&lt;/span&gt;&amp;lt;div class=&quot;sub-total&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;(you will need to disable rich text editor or write in source view with Text Format=Full HTML)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/ol&gt;
&lt;br /&gt;
c) We are done with form building here, now time to add some code in template.php file:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:php&quot;&gt;// This will display form element in a multi column table

function adibf_table_element($variables) {
  $element = $variables[&#39;element&#39;];
  $header = array();
  $header_complete = false;
  $rows = array();
  
  foreach (element_children($element) as $child) {
    $child_element = $element[$child];
   
 $rowCustomData = $child_element[&#39;#row_title&#39;];
 $rowCustomData = json_decode($rowCustomData);
   
    $row = array($rowCustomData-&amp;gt;ID);
 
    foreach (element_children($child_element) as $grandchild) {
      
      if (!$header_complete &amp;amp;&amp;amp; isset($element[&#39;#row_titles&#39;])) {
       if($child_element[$grandchild][&#39;#type&#39;] == &#39;markup&#39;) {
   $theKey = trim(strip_tags($child_element[$grandchild][&#39;#markup&#39;]));
   $theTitle = &#39;&#39;;
   
   switch($theKey) {
    case &#39;Name&#39;:
     $theTitle = t(&#39;Item&#39;);
     break;
    
    case &#39;Rate&#39;:
     $theTitle = t(&#39;Rate (usd)&#39;);
     break;
    
    case &#39;Quantity&#39;:
     $theTitle = t(&#39;Quantity&#39;);
     break;
   }
   
   if($element[&#39;#column_titles&#39;][$grandchild] == &#39;sub-total&#39;)
    $theTitle = t(&#39;Sub Total&#39;);
   
   $header[]  = array(&#39;data&#39; =&amp;gt; $theTitle, &#39;class&#39; =&amp;gt; $element[&#39;#column_titles&#39;][$grandchild]);
  } else {
         $header[]  = array(&#39;data&#39; =&amp;gt; t($element[&#39;#row_titles&#39;][$grandchild]), &#39;class&#39; =&amp;gt; $element[&#39;#column_titles&#39;][$grandchild]);
  }
      }
  
  if($child_element[$grandchild][&#39;#type&#39;] == &#39;markup&#39;) {
   if(trim(strip_tags($child_element[$grandchild][&#39;#markup&#39;])) == &#39;Name&#39;)
    $child_element[$grandchild][&#39;#markup&#39;] = $rowCustomData-&amp;gt;title;
  
   if(trim(strip_tags($child_element[$grandchild][&#39;#markup&#39;])) == &#39;Rate&#39;)
   $child_element[$grandchild][&#39;#markup&#39;] = $rowCustomData-&amp;gt;rate;
  
   if(trim(strip_tags($child_element[$grandchild][&#39;#markup&#39;])) == &#39;Color&#39;)
   $child_element[$grandchild][&#39;#markup&#39;] = $rowCustomData-&amp;gt;color;
  
   if(trim(strip_tags($child_element[$grandchild][&#39;#markup&#39;])) == &#39;Dimension&#39;)
   $child_element[$grandchild][&#39;#markup&#39;] = $rowCustomData-&amp;gt;dimension;
  }
  
     $row[] = array(&#39;data&#39; =&amp;gt; drupal_render($child_element[$grandchild]));
    }

    $header_complete = true;
    $rows[] = $row;
  }

  array_unshift($header, array(&#39;class&#39; =&amp;gt; &#39;row-title&#39;, &#39;data&#39; =&amp;gt; t(&#39;Code&#39;)));
  return theme(&#39;table&#39;, array(&#39;header&#39; =&amp;gt; $header, &#39;rows&#39; =&amp;gt; $rows));
}

// This will show posted results in multi column table

function adibf_webform_submission_render_alter(&amp;amp;$renderable) {
 if (isset($renderable[&#39;#submission&#39;])) {
  foreach (element_children($renderable) as $key) {
   $tableRows = array();
   
   if ($renderable[$key][&#39;#webform_component&#39;][&#39;type&#39;] == &#39;table_element&#39;) {
    $cid = $renderable[$key][&#39;#webform_component&#39;][&#39;cid&#39;];
    
    foreach($renderable[&#39;#submission&#39;]-&amp;gt;data[$cid][&#39;value&#39;][&#39;rows&#39;] as $row) {
     $data = strip_tags($row[0]);
     $quantity = $row[&#39;quantity&#39;];
     
     $objData = json_decode($data);
     $subTotal = $objData-&amp;gt;rate * $quantity;
     $tableRows[] = array($objData-&amp;gt;ID, $objData-&amp;gt;title, $objData-&amp;gt;rate, $quantity, $subTotal);
    }
    
    $tableHeader = array(&#39;ID&#39;, &#39;Title&#39;, &#39;Rate&#39;, &#39;Quantity&#39;, &#39;Sub Total&#39;);
    
    $theTable = array(
     &#39;header&#39; =&amp;gt; $tableHeader,
     &#39;rows&#39; =&amp;gt; $tableRows,
    );
    
    $renderable[$key][&#39;#markup&#39;] = theme(&#39;table&#39;, $theTable);
   }
  }
 }
}
&lt;/pre&gt;
&lt;br /&gt;
First code block will display form element visually in a multi column table with one text field for quantity in each row, the second block is for the posted results.&lt;br /&gt;
&lt;br /&gt;
d) The last step is to add a little jQuery somewhere in the theme so after entering quantity, sub total column value would be changed. You can also add a feature to show Net Total somewhere on the page:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:php&quot;&gt;jQuery(&#39;.webform-component-table_element .form-text&#39;).change(function() {
  var elems = jQuery(&#39;.webform-component-table_element .form-text&#39;);
  
  var totalAmount = 0;
  for(var i=0; i&amp;lt;elems.length; i++) {
   totalAmount += table_element_calculate(elems[i]);
  }
  
  jQuery(&#39;#net_total&#39;).html(totalAmount);
 });


function table_element_calculate(elem) {
 var sPrice = jQuery(elem).parents(&#39;td&#39;).prev().text();
 var hTotal = jQuery(elem).parents(&#39;td&#39;).next();
 
 var p = 0;
 
 try {
  p = sPrice * jQuery(elem).val();
  
  if(isNaN(p))
   p = 0;
  
  if(p &amp;gt; 0)
   hTotal.find(&#39;.sub-total&#39;).html(p);
  // alert(p);
 } catch(e) {}
 
 return p;
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;i&gt;Note: I just copied pasted these codes from a project that I did some months ago, so if something don&#39;t work please post in comments. Thanks.&lt;/i&gt;</content><link rel='replies' type='application/atom+xml' href='http://helperclass.blogspot.com/feeds/2939022638997093974/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://helperclass.blogspot.com/2012/06/drupal-7-webform-with-item-catalog.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/33304191/posts/default/2939022638997093974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/33304191/posts/default/2939022638997093974'/><link rel='alternate' type='text/html' href='http://helperclass.blogspot.com/2012/06/drupal-7-webform-with-item-catalog.html' title='Drupal 7 Webform with an item catalog table element'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNl1F6ePtpL39tuDJdxrWL15zzYv6fKwR5HeZW88EQuVFQ-7E9T0TvPohsK3DoYHmsjRv6bkwCOanx5z_Z214U6WC2soYBN9-e87Yk37cbRHaa7qv0tM3FxoKXNLuoFRuoX0rN/s72-c/Drupal_custom_webform_element.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-33304191.post-7429588912865755682</id><published>2011-11-13T17:27:00.000-08:00</published><updated>2011-11-14T01:46:53.033-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><title type='text'>Creating separate sub menu in WordPress 3</title><content type='html'>I needed to create a split menu for one of my projects where top level menu items were in a horizontal menu and children of active menu in a sidebar. Its a super simple task in Joomla but I couldn&#39;t find anything out of the box in WordPress.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPZIAA5mP3T2GJW-8kfW7npRJvy3xOJ7HK28P0NnTzkNWOfBrVL8Lcsypdii_05dbtDHLRv21y1wWI4STxaR4SvrBvYUqPzChjgUAm61XjU64sdL4lgCmO3C4A-PCXh8PKZOIy/s1600/split-menu.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPZIAA5mP3T2GJW-8kfW7npRJvy3xOJ7HK28P0NnTzkNWOfBrVL8Lcsypdii_05dbtDHLRv21y1wWI4STxaR4SvrBvYUqPzChjgUAm61XjU64sdL4lgCmO3C4A-PCXh8PKZOIy/s1600/split-menu.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
I managed to resolve this issue using&amp;nbsp;wp_list_pages, but it was not sorted according to custom menu sort order.&amp;nbsp;So I made this simple custom walker and it worked.&lt;br /&gt;
&lt;br /&gt;
(&lt;a href=&quot;http://wordpress.stackexchange.com/questions/16818/add-has-children-class-to-parent-li-when-modifying-walker-nav-menu&quot; target=&quot;_blank&quot;&gt;This&lt;/a&gt; link helped me in adding has_children property to menu items). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:php&quot;&gt;class SplitMenu_Walker_Nav_Menu extends Walker_Nav_Menu {
 var $startMenu = false;
 
 function start_lvl(&amp;amp;$output, $depth) {
  
 }

 function end_lvl(&amp;amp;$output, $depth) {
  $this-&amp;gt;startMenu = false;
 }
 
 function start_el(&amp;amp;$output, $item, $depth, $args) {
  if(($args-&amp;gt;has_children &amp;amp;&amp;amp; $item-&amp;gt;current) || $item-&amp;gt;current_item_parent)
   $this-&amp;gt;startMenu = true;
  
  if($this-&amp;gt;startMenu &amp;amp;&amp;amp; $depth &amp;gt; 0)
    parent::start_el($output, $item, $depth, $args);
 }

 function end_el(&amp;amp;$output, $item, $depth) {
  if( $this-&amp;gt;startMenu )
    parent::end_el($output, $item, $depth);
 }
 
 function display_element( $element, &amp;amp;$children_elements, $max_depth, $depth=0, $args, &amp;amp;$output ) {
        $id_field = $this-&amp;gt;db_fields[&#39;id&#39;];
        if ( is_object( $args[0] ) ) {
            $args[0]-&amp;gt;has_children = ! empty( $children_elements[$element-&amp;gt;$id_field] );
        }
        return parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
This code is tested with single level of sub menus only.&lt;/blockquote&gt;
&lt;br /&gt;
&lt;b&gt;How to use:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Copy above code and paste into your theme&#39;s functions.php&lt;/li&gt;
&lt;li&gt;Pass an object of walker class to your &#39;wp_nav_menu&#39; function:&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: php&quot;&gt;wp_nav_menu(
    array (
        &#39;menu&#39;            =&amp;gt; &#39;main-menu&#39;,
        &#39;walker&#39;          =&amp;gt; new SplitMenu_Walker_Nav_Menu
    )
);
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://helperclass.blogspot.com/feeds/7429588912865755682/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://helperclass.blogspot.com/2011/11/creating-separate-sub-menu-in-wordpress.html#comment-form' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/33304191/posts/default/7429588912865755682'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/33304191/posts/default/7429588912865755682'/><link rel='alternate' type='text/html' href='http://helperclass.blogspot.com/2011/11/creating-separate-sub-menu-in-wordpress.html' title='Creating separate sub menu in WordPress 3'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPZIAA5mP3T2GJW-8kfW7npRJvy3xOJ7HK28P0NnTzkNWOfBrVL8Lcsypdii_05dbtDHLRv21y1wWI4STxaR4SvrBvYUqPzChjgUAm61XjU64sdL4lgCmO3C4A-PCXh8PKZOIy/s72-c/split-menu.png" height="72" width="72"/><thr:total>10</thr:total></entry></feed>