title: How to get categories in wordpress
body: <p>I want to get all categories in wordpress site but separately parent and child categories(in such way it's easily for me to style). In the following code I get parent categories but all children categories are repeated for every parent.
  Thanks!</p>
  
  <pre><code>&lt;?php
  $args = array(
      'orderby' =&gt; 'name',
      'parent' =&gt; 0
  );
  $categories = get_categories( $args );
  $categories_sub = get_categories();
  foreach ( $categories as $category ) {
      echo '&lt;ul class=" span-5 colborder list_main "&gt; &lt;a href="' . get_category_link(     $category-&gt;term_id ) . '"&gt;' . $category-&gt;name . '&lt;/a&gt;&lt;br/&gt;';
      foreach ( $cat-&gt;parent &gt; 1 and $categories_sub as $cat) {
          $temp=$category-&gt;name + '/';
          if(get_category_parents($cat)==$temp) {
              echo '&lt;a href="' . get_category_link( $cat-&gt;term_id ) . '"&gt;' . $cat-&gt;name . '&lt;/a&gt;&lt;br/&gt;';
          }
          $temp="";
      }
      echo '&lt;/ul&gt;'; 
  }
  ?&gt;
  </code></pre>