我知道这里有几个关于Wordpress短代码库排序的问题,例如this,但我找不到任何解决方案似乎都有效。我正在页面模板上创建一个库,其中包含来自自定义后期类型的库中的图像。我有一部分工作,并使用页面模板创建库,但是,图像按ID继续排序,升序。
我创建的功能按照发布日期,从最新到最旧,按时间顺序将图像ID添加到图库短代码。我已经回显了ids属性来验证和接收输出:177,239,236,235,234,232,230,231。但是,当图像出现在图库中时,它们被列为177,230,231,232 ,234,235,236和239.画廊短代码状态// 'ids' is explicitly ordered, unless you specify otherwise.
,但显然没有发生。
我尝试使用orderby='post__in'
和order='ASC'
在短代码中指定order和orderby属性
以及为此特定页面创建新的图库短代码,并在this response中进行建议的更改。这些都没有产生任何影响。
非常感谢任何帮助。提前谢谢。
--- --- UPDATE
根据要求,以下是代码段。这是形成模板文件的库短代码的函数。我添加了一个新的[portfolio_gallery]短代码,所以我可以修改它,并且仍然在其他地方使用标准[gallery]短代码。
function portfolio_slider_images($post_id) {
$size=large;
$num=1;
$cat = get_post_meta($post_id, 'portfolio_category', true);
//Query Args
$query_args = array('post_type' => 'portfolio');
//Query posts of portfolio_type with proper category
$posts = new WP_Query($query_args);
//$posts= query_posts(array('taxonomy'=>'portfolio_type', 'slug'=>$cat, 'post_type' => 'portfolio'));
//Count to track initial ID added to shortcode
$count = 0;
//Start gallery shortcode - using new shortcode [portfolio_gallery]
$gallery= '[portfolio_gallery columns="3" size="medium" link="file" data-rel="lightbox" ids="';
//Cycle through each post that met requirements
while ( $posts->have_posts() ) : $posts->the_post();
//foreach( $posts as $post ) {
echo($post->ID. " ");
$categories = get_the_terms($post->ID, 'portfolio_type');
foreach($categories as $category){
if($category->slug == $cat){
//Check for gallery in post, if present, take those images
if ( get_post_gallery($post->ID) ){
$post_gallery = get_post_gallery( $post->ID , false );
if($count == 0){$gallery = $gallery . $post_gallery['ids'];}
else{$gallery = $gallery . ', '. $post_gallery['ids'];}
}
//If no gallery in post, pull images attached to post
else if ( $images = get_children(array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'numberposts' => $num,
'post_mime_type' => 'image',)))
{
$incount = 1;
foreach( $images as $image ) {
if ($incount == $num) {$incount= 1;}
if($count == 0){$gallery = $gallery . $image->ID;}
else{$gallery = $gallery . ', '. $image->ID;}
$incount++;
}
}
//If no images, do nothing - echo left from testing
else {
//echo "No Image";
}
$count++;
}
}
endwhile;
//}
//Close out gallery shortcode
$gallery = $gallery . '"]';
//echo($gallery);
echo('<div class="portfolio-gallery">'.do_shortcode($gallery).'</div');
//wp_reset_query();
wp_reset_postdata();
}
[portfolio_gallery]短代码的代码目前与media.php文件中[gallery]短代码的代码相同。我为该功能尝试的更改未纠正排序。在上面的块中,我尝试添加orderby='post__in' order='ASC'
以及任何其他orderby列表。这些都没有改变图像的顺序。
希望这些新增功能有所帮助。谢谢!