时间:2015-04-23 08:48:10

标签: php jquery html css wordpress

我有一个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-## -->

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

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

2 个答案:

答案 0 :(得分:0)

以下是将所有帖子图片作为图库添加到单个帖子中的代码:

<?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>';
        }

    }
}
?>

答案 1 :(得分:0)

尝试使用Jquery来执行此操作。它可能会解决您的问题。

$(document).ready(function(){
      var img='';
      $('img').each(function(){
          var imgSrc = $(this).attr('src');
          $(this).remove();
          console.log(imgSrc);
          img += '<img src="'+imgSrc+'">';
      });

  $("#imgs").html(img); // this id is targeted div
});

<div id="imgs"></div>