-6ren">
gpt4 book ai didi

php - 帖子内容中的目标图像

转载 作者:行者123 更新时间:2023-11-28 08:00:14 25 4
gpt4 key购买 nike

我有一个 Wordpress 网站,位于“content.single.php”(所有单个帖子都拼凑在一起)我的主题是先放特色图片再放内容(然后是底部的后退/下一个导航)。

html

<article id="post-<?php the_ID(); ?>"<?php post_class('col-md-12'); ?>>
<div class="container">

<?php
$thumb = get_post_thumbnail_id();
$img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)
$image = aq_resize( $img_url, 1200, 720, true ); //resize & crop the image
?>

<?php if($image) : ?>
<img class="img-responsive singlepic" src="<?php echo $image ?>"/>
<?php endif; ?>

<div class="entry-content">
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>

<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'web2feel' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->

</div>
</article><!-- #post-## -->

我想以完全相同的方式在特色图片下方显示帖子中的所有图片。

是否有针对帖子内容中的图像的功能?

最佳答案

这是一个代码,用于将单个帖子中的所有帖子图像作为图库获取:

<?php if ( $post->post_type == 'data-design' && $post->post_status == 'publish' ) {
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id()
) );

if ( $attachments ) {
foreach ( $attachments as $attachment ) {
$class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type );
$thumbimg = wp_get_attachment_link( $attachment->ID, 'thumbnail-size', true );
echo '<li class="' . $class . ' data-design-thumbnail">' . $thumbimg . '</li>';
}

}
}
?>

关于php - 帖子内容中的目标图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29818235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com