【发布时间】:2019-05-23 17:51:52
【问题描述】:
我正在尝试在特定父页面的子页面上显示所有图像附件,即第 10、11 和 12 页上的所有图片。
Projects (Page ID: 5)
- Project 1 (Page ID: 10)
- Project 2 (Page ID: 11)
- Project 3 (Page ID: 12)
这是我目前所拥有的,它可以显示网站上的所有图像:
<?php
$args = array(
'post_parent' => 0,
'post_type' => 'attachment',
'numberposts' => -1
);
$images = get_children( $args );
if ( empty($images) ) {
// no attachments here
} else {
foreach ( $images as $attachment_id => $attachment ) {
echo wp_get_attachment_image( $attachment_id, 'full' );
}
}
?>
但是,如果我添加帖子父 ID (5),则什么也不会出现:
<?php
$args = array(
'post_parent' => 5,
'post_type' => 'attachment',
'numberposts' => -1
);
$images = get_children( $args );
if ( empty($images) ) {
// no attachments here
} else {
foreach ( $images as $attachment_id => $attachment ) {
echo wp_get_attachment_image( $attachment_id, 'full' );
}
}
?>
任何建议都会很有帮助!
【问题讨论】:
标签: php html wordpress foreach wordpress-theming