好的,我已经设置了一些代码,用于搜索ID 8的所有子页面,然后将这些页面的所有附件(在库中)输出为无序列表项。到目前为止,您可以在这里看到 http://goo.gl/eq4UF 的效果。
我遇到的问题是我需要在每个页面之前包含每个页面的标题,以便您可以轻松识别哪些图像位于哪个页面下方。通常我只会添加它,但是列表项使用砖石,并使用一些JS在整个页面上放置,因此它们永远不会出现在列表中的第一个图像旁边。
因此,我将在每个页面中添加页面标题 <li>
在<ul>
中,这将允许标题与每个图像一起运行,但我不知道如何将其包含在 wp get 附件图像功能中。the_title
和wp_title
在此循环中都不起作用。 apply_filters( 'the_title', $attachment->post_title );
显然采用图像标题,但是使用页面标题有什么好处吗?
提前感谢并希望这是有道理的,R
<?php $postslist = get_pages('number=9999&sort_order=DESC&sort_column=post_date&child_of=8');
foreach ($postslist as $post) :
setup_postdata($post); ?>
<ul class="main-projects-list">
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'orderby' => 'menu_order',
'order' => 'ASC',
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<li class="each-image">';
echo wp_get_attachment_image( $attachment->ID, 'large' );
echo '<p>';
echo apply_filters( 'the_title', $attachment->post_title );
echo '</p></li>';
}
}
?>
</ul>
<?php endforeach; ?>
你可以试试这个:
<?php $postslist = get_pages('number=9999&sort_order=DESC&sort_column=post_date&child_of=8');
foreach ($postslist as $post) :
setup_postdata($post); ?>
<ul class="main-projects-list">
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'orderby' => 'menu_order',
'order' => 'ASC',
);
$attachments = get_posts( $args );
if ( $attachments ) {
$post_title = get_the_title($post->ID); // We get the post title
foreach ( $attachments as $attachment ) {
$img_title = apply_filters( 'the_title', $post_title . ' - ' . $attachment->post_title ); // We create the image title with the 2 strings
echo '<li class="each-image">';
echo wp_get_attachment_image( $attachment->ID, 'large' , false, array('title' => $img_title));
echo '<p>';
echo $img_title;
echo '</p></li>';
}
}
?>
</ul>
<?php endforeach; ?>