从自定义字段切换列表项的输出顺序

时间:2012-02-10 07:57:29

标签: php list custom-fields

如何切换此输出列表项的顺序。我将自定义字段值设置为“001,value”“002,value”,但最低的数字在列表中排在最后,我首先需要它。

 <?php
     $album = get_post_meta($post->ID, "album", false);
     $album_list = get_post_meta($post->ID, "album_list", false); 
     foreach ($album_list as $album_list) {
         list($key, $value) = explode(',',$album_list);
         $indexed_album_list[$key] = $value;
     }
     foreach ( $album as $each_album) {
         list($key,$album) = explode(',',$each_album);
         echo '<div>'.$album.'</div>';
         echo '<div>';
         if ($album_list = $indexed_album_list[$key]) {
             echo $album_list;
         }  
         else {
             echo '&nbsp';
         }
         echo '</div>';
     }
?>   

继承人数据...... Array ( [0] => 002,Curtis [1] => 001,Get Rich Or Die Tryin [2] => 003,The Massacre [3] => 004,Before I Self Destruct ) Array ( [0] => 001, [1] => 002, [2] => 003, [3] => 004,

1 个答案:

答案 0 :(得分:0)

Doh只需在第四行添加sort($album);即可。