2013-07-10 35 views
0

有沒有辦法在wordpress輸出中將自定義字段設置爲無序列表?在WordPress中輸出自定義字段內容爲ul

使用此代碼作爲參考,它將每個單詞作爲單獨的列表項輸出,是否有辦法讓它使用逗號或其他字符作爲破壞列表的方式?

Wordpress - output custom field as ul list

林很新的PHP。

<?php 
$list_items = get_post_meta($post->ID, 'idid', true); 

    if($list_items){ 
     $list_items2 = explode(" ", $list_items); 
      echo '<ul>'; 
       foreach($list_items2 as $list_item) 
        echo '<li>' . $list_item . '</li>'; 
      echo '</ul>'; 

    } 

?> 
+0

嘗試將所有資源放在此頁面中。不要添加其他鏈接,所以人們不會迷路。 – aldux

+0

感謝您的建議 – Bucthree

回答

0

所以你不想要一個HTML無序列表。您只想以某種方式輸出列表,例如使用分隔符。這是非常基本的:

<?php 
$list_items = get_post_meta($post->ID, 'idid', true); 
    if($list_items){ 
     $list_items2 = explode(" ", $list_items); 
     $sep = ""    
     foreach($list_items2 as $list_item) { 
      echo $sep . $list_item; 
      $sep = ", "; // this can be any char or string, or number...etc. 
     } 


    } 

?> 
+0

我在sep =「」行和sep =「,」;行... – Bucthree

+0

忘記$符號。多年沒有PHP編程。 – aldux

+0

也需要添加;在$ sep =「」結尾 – Bucthree

0

越來越接近......但它在每個單詞後面都加逗號。我想要一個句子,然後能夠在句子後面加上逗號,以便將下一句放在它下面的一行中。

所以,我會在自定義字段中鍵入此: Lorem存有悲坐阿梅德,Consectetur adipiscing ELIT,Quisque euismod lectus簡歷commodo sollicitudin

,它會輸出這樣的:

  • 的Lorem存有悲坐阿梅德
  • Consectetur adipiscing ELIT Quisque
  • Euismod lectus簡歷commodo sollicitudin
相關問題