如何从所有subpages 特定页面ID的?
示例:
特定页面
孩子(带附件)
$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => -1,
\'post_status\' => null,
\'post_parent\' => null
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $post ) {
setup_postdata( $post );
the_title();
the_attachment_link( $post->ID, false );
the_excerpt();
}
}
使用下面的代码几乎可以做到:$mypages = get_pages( \'child_of=19\' );
foreach ( $mypages as $mypage ) {
$attachments = get_children( array(
\'post_parent\' => $mypage->ID,
\'numberposts\' => 1,
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\',
\'orderby\' => \'rand\'
) );
if ( $attachments ) {
foreach ( $attachments as $post ) {
setup_postdata($post);
the_title();
the_attachment_link( $post->ID, false );
the_excerpt();
}
}
}
然而,还有两个问题:限制total photos 拉动。使用\'numberposts\'
仅限制从每篇帖子中提取的图像数量Orderby => rand 仅随机化每篇文章中的图像。我想随机改变所有东西的顺序