2014-07-10 29 views
-1

我目前有以下代碼。代碼回顯了WordPress數據庫中包含的類別列表。代碼是正常工作,但我需要幫助樣式。將PHP Loop語句放入無序列表中3列

<?php 
$regions = get_terms($taxonomies, $args); 

    ?> 

    <h3>Regions</h3> 

    <ul> 
     <?php foreach ($regions as $region) { 
      echo '<li><a href="' . esc_attr(get_term_link($region, $taxonomy)) . '" title="' . sprintf(__("View all posts in %s"), $region->name) . '" ' . '><font color="#bf9764">' . $region->name.'</font></a></li>'; 
      } 
     ?> 
    </ul> 

輸出顯示一個單一的無序列表,但我希望將此列表分成3個相等的列。見下面的例子。

1. Category 1 | 4. Category 4 | 7. Category 7 
2. Category 2 | 5. Category 5 | 8. Category 8 
3. Category 3 | 6. Category 6 | 9. Category 9 

我很害怕CSS。謝謝你的幫助!

回答

0

你可以使用CSS3 columns - JSFiddle Demo

CSS

ul { 
    width:300px; 
    -webkit-column-count: 3; 
    -moz-column-count: 3; 
    column-count: 3; 
} 

HTML

<ul> 
    <li>Category 1</li> 
    <li>Category 2</li> 
    <li>Category 3</li> 
    <li>Category 4</li> 
    <li>Category 5</li> 
    <li>Category 6</li> 
    <li>Category 7</li> 
    <li>Category 8</li> 
    <li>Category 9</li> 
</ul> 
+0

謝謝您的時間。工作很棒! – Daniel