从wordpress post获取所有图像
使用此函数,我可以通过echo get_the_first_image()从帖子中获取第一张图像: 函数get_first_image(){ 全球$员额,$员额; $first_img=''; ob_start(); ob_end_clean(); $output=preg_match_all('//i',$post->post_content,$matches); $first_img=$matches[1][0]; if(empty($first_img)){//定义默认图像 $first_img=“path/to/default/image.jpg”; } 返回$first\u img; }从wordpress post获取所有图像,wordpress,image,post,Wordpress,Image,Post,使用此函数,我可以通过echo get_the_first_image()从帖子中获取第一张图像: 函数get_first_image(){ 全球$员额,$员额; $first_img=''; ob_start(); ob_end_clean(); $output=preg_match_all('//i',$post->post_content,$matches); $first_img=$matches[1][0]; if(empty($first_img)){//定义默认图像 $first_
我可以更改此代码以从帖子中获取数组或其他合适的图像吗?您好,我正在搜索相同的内容,下面的代码从帖子中获取所有附加的图像(请确保在while循环中使用此代码)
希望这能有所帮助。它还与自定义帖子类型结合使用Hi a go我在搜索相同的东西,下面的代码从帖子中获取所有附加图像(请确保在while循环中使用此代码)
<ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<li>';
echo wp_get_attachment_image( $attachment->ID, 'full' );
echo '<p>';
echo apply_filters( 'the_title', $attachment->post_title );
echo '</p></li>';
}
}
endwhile; endif; ?>
</ul>
希望这能有所帮助。它还与自定义帖子类型结合使用Hi a go我在搜索相同的东西,下面的代码从帖子中获取所有附加图像(请确保在while循环中使用此代码)
<ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<li>';
echo wp_get_attachment_image( $attachment->ID, 'full' );
echo '<p>';
echo apply_filters( 'the_title', $attachment->post_title );
echo '</p></li>';
}
}
endwhile; endif; ?>
</ul>
希望这能有所帮助。它还与自定义帖子类型结合使用Hi a go我在搜索相同的东西,下面的代码从帖子中获取所有附加图像(请确保在while循环中使用此代码)
<ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<li>';
echo wp_get_attachment_image( $attachment->ID, 'full' );
echo '<p>';
echo apply_filters( 'the_title', $attachment->post_title );
echo '</p></li>';
}
}
endwhile; endif; ?>
</ul>
希望这能有所帮助。它与定制的帖子类型结合在一起,对我来说也很有效
<ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<li>';
echo wp_get_attachment_image( $attachment->ID, 'full' );
echo '<p>';
echo apply_filters( 'the_title', $attachment->post_title );
echo '</p></li>';
}
}
endwhile; endif; ?>
</ul>
如果您有任何疑问,请在此处发表评论
如果您有任何疑问,请在此处发表评论
如果您有任何疑问,请在此处发表评论
如果您有任何疑问,请在此发表评论