我的最终目标是创建一个图库页面,自动上传附加到网站上任何已发布帖子的图像。在我的搜索中,我找到了下面的代码(also found here),将它放在我的fucntions.php中并且效果很好,但我不能使用任何其他图库输出选项(大小,顺序,顺序等)。 ..)以我想要的方式帮助组织图像。看看代码似乎我需要添加/引入其他输出选项,但对此非常新,我不知道如何修改下面的代码来实现这一点。有什么想法吗?
/**
* Usage: [catgallery cat="4,5"]
* Attribute: array of category IDs
*/
add_shortcode('catgallery', 'wpse_70989_cat_gallery_shortcode');
function wpse_70989_cat_gallery_shortcode($atts)
{
// $return = ''; // DEBUG: enable for debugging
$arr = array();
$cat_in = explode( ',', $atts['cat'] );
$catposts = new WP_Query( array(
'posts_per_page' => -1
, 'category__in' => $cat_in
) );
foreach( $catposts->posts as $post)
{
// DEBUG: Enable the next line to print the post title
// $return .= '<strong>' . $post->post_title . '</strong><br />';
$args = array(
'post_type' => 'attachment'
, 'numberposts' => -1
, 'post_status' => null
, 'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments)
{
foreach ( $attachments as $attachment )
{
// DEBUG: Enable the next line to debug the attachement object
// $return .= 'Attachment:<br /><pre>' . print_r($attachment, true) . '</pre><br />';
$arr[] = $attachment->ID;
}
}
}
// DEBUG: Disable the next line if debugging
$return = do_shortcode( '[gallery include="' . implode( ',', $arr ) . '"]' );
return $return;
}
答案 0 :(得分:0)
默认的Wordpress库提供了指定here的orderby和size选项,因此只需在do_shortcode行中添加您喜欢的选项。
如果你想要更复杂的东西,你可能需要开发一个自定义插件。