切换自定义字段中列表项的输出顺序
如何切换输出列表项的顺序。我将自定义字段值设置为“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 ' ';
}
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Doh 只需要在第四行添加
sort($album);
就可以了。Doh just had to add
sort($album);
on the fourth line and it worked.