我在短代码中有以下库顺序:
[gallery ids="1996,2431,372,447,645,641,647,642,649,643,650,648,653,697,652,390"]
我有一个功能,可以创建一个更漂亮的画廊:
add_filter(\'post_gallery\', \'pab_gallery\');
function pab_gallery($attr) {
global $post;
extract(shortcode_atts(array(
//\'order\' => \'ASC\',
\'orderby\' => \'menu_order DESC, ID ASC\',
\'id\' => $post->ID,
\'columns\' => 3,
\'size\' => \'thumbnail\',
\'include\' => \'\',
\'exclude\' => \'\'
), $attr));
$attachments = get_children( array(\'post_parent\' => $id, \'post_status\' => \'inherit\', \'post_type\' => \'attachment\', \'post_mime_type\' => \'image\', \'orderby\' => $orderby) );
#print_r($attachments);
$output = \'<div class="gallery">\';
$output .= \'<ul class="clearfix">\';
foreach ( $attachments as $id => $attachment ) {
$link = wp_get_attachment_link($id, $size, false, true);
$output .= sprintf(\'<li>%s</li>\', $link);
}
return $output.\'</ul></div>\';
}
我对此有两个问题:首先,ID指定的顺序被完全忽略,即使我传递了“orderby”。此外,函数也不会显示图像#1996,即使它附在帖子上(我认为在为短代码提供ID时,无论如何都不需要)。这是我从插件收到的命令:
Array ( [0] => 2431 [1] => 656 [2] => 652 [3] => 651 [4] => 648 [5] => 650 [6] => 643 [7] => 649 [8] => 642 [9] => 647 [10] => 641 [11] => 645 [12] => 629 [13] => 676 )
正如您所看到的,它既不是我使用短代码指定的顺序,也不是以任何方式升序或降序。
我希望函数按照在短代码中指定的确切顺序显示ID。这可能吗?