Php Wordpress-在';wp-get-attachment-image';
好的,我设置了一段代码,搜索ID为8的子页面,然后将这些页面的所有附件(在库中)作为无序列表项输出。你可以在这里看到目前为止的效果 我遇到的问题是,我需要在每一页之前包含每一页的标题,这样你就可以很容易地确定哪一页下面有哪些图片。通常我只会将其添加到列表中,但列表项都使用砖石结构,并使用一些JS将其放置在整个页面中,因此它们永远不会出现在列表中第一个图像的旁边 因此,我将在每一页中添加该页的标题Php Wordpress-在';wp-get-attachment-image';,php,wordpress,Php,Wordpress,好的,我设置了一段代码,搜索ID为8的子页面,然后将这些页面的所有附件(在库中)作为无序列表项输出。你可以在这里看到目前为止的效果 我遇到的问题是,我需要在每一页之前包含每一页的标题,这样你就可以很容易地确定哪一页下面有哪些图片。通常我只会将其添加到列表中,但列表项都使用砖石结构,并使用一些JS将其放置在整个页面中,因此它们永远不会出现在列表中第一个图像的旁边 因此,我将在每一页中添加该页的标题 中的将允许标题与每个图像一起运行,但我不知道如何将其包含在wp get attachment ima
中的
将允许标题与每个图像一起运行,但我不知道如何将其包含在wp get attachment image函数中。和wp\u title
在这个循环中都不起作用<代码>应用\u过滤器('the \u title',$attachment->post\u 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 ) {
$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; ?>
非常感谢。我需要标题和图像标题作为单独的变量,因为我想在li class=“每个图像”之后加载页面标题。你能帮忙吗?设法编辑你放在一起的内容:$main\u page\u title=apply\u filters('the\u title',$post\u title);$img\u title=apply\u过滤器('the\u title',$attachment->post\u title);echo';echo$main\u page\u title;echo wp_get_attachment_image($attachment->ID,'large',false,array('title'=>$img_title));回声“”;echo$img_标题;回声“ ”代码>使用$img\u title=apply\u过滤器('the\u title',$attachment->post\u title)
获取第二个变量中的图像标题。然后您可以在附件函数中以这种方式使用它来获取连接字符串数组('title'=>$post\u title.-'.$img\u title)
,与下面的html段落中相同。
<?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; ?>