【发布时间】:2015-04-26 11:21:37
【问题描述】:
我的 wordpress 主题、单篇文章页面(显示单篇文章的页面)中有以下代码。
<article id="post-<?php the_ID(); ?>"<?php post_class('col-md-12'); ?>>
<div class="container">
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<?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; ?>
<?php if ( $post->post_type == 'data-design' && $post->post_status == 'publish' ) {
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>';
}
}
}
?>
<div class="entry-content">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'web2feel' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
</div>
</article><!-- #post-## -->
它将帖子标题和特色图片作为大图片,然后发布内容,然后是其余内容。
我想定位内容中的图像,并以与显示特色图像相同的方式显示它们。
*NOTE - 对 'if ( $attachments ) { ...' 函数的更改不会改变任何东西(也不会完全删除它),所以我不确定该部分的作用。唯一影响内容的代码是调用时('')
【问题讨论】:
-
你可以在没有 php 的情况下做到这一点,在编辑器中只需为帖子中的图像设置与特色图像相同的 css 类。或者您可以将这些 css 类的 css 属性复制到
.entry-content img。 -
php 代码 $php if($image) 设置图像大小/裁剪等,所以不需要 php 来遵循与 feature-image 相同的类吗?你的方法有效,但质量非常低(它在后期 php 中引入了很小的图像(即使它是一个大图像)并且添加 100% 宽度只会以低质量放大它
-
想通了!混合了您所说的内容和一些代码更改修复了它,感谢您的帮助