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

发布于 2025-01-03 21:42:56 字数 996 浏览 2 评论 0原文

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

 <?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] => 003,The Massacre [3] => 004,在我自毁之前)数组([0] => 001,[1] => 002,[2] => 003, [3] => 004,

How can switch the order this outputs the list items. I have my custom field values set to "001,value" "002,value" but the lowest number comes out last in the list and I need it first.

 <?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 ' ';
         }
         echo '</div>';
     }
?>   

Heres the returend data...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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我三岁 2025-01-10 21:42:56

Doh 只需要在第四行添加 sort($album); 就可以了。

Doh just had to add sort($album); on the fourth line and it worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文