Css 显示错误的图像,尽管链接正确

Css 显示错误的图像,尽管链接正确,css,wordpress,wordpress-theming,lightbox,Css,Wordpress,Wordpress Theming,Lightbox,这是我目前正在处理的一个非常奇怪的问题:我试图在我的wordpress主题中实现一个灯箱效果。遵循本教程(使用的CSS代码如下:)。我已经试过了,效果很好。 但我并不想把这种效果应用到特色图片上,而是应用到帖子中的所有图片上。我已经更改了代码以满足我的需要,如果我在帖子中只有一张图片,但如果我添加了另一张(或多张)图片,则代码可以正常工作,问题就出现了: 当我点击一张图片时,不管是哪一张,它只是第一张显示在大版本中的图片。但是当我检查源代码时,会为每个图片的大版本调用相关图片。 下面是我用来制作

这是我目前正在处理的一个非常奇怪的问题:我试图在我的wordpress主题中实现一个灯箱效果。遵循本教程(使用的CSS代码如下:)。我已经试过了,效果很好。
但我并不想把这种效果应用到特色图片上,而是应用到帖子中的所有图片上。我已经更改了代码以满足我的需要,如果我在帖子中只有一张图片,但如果我添加了另一张(或多张)图片,则代码可以正常工作,问题就出现了:
当我点击一张图片时,不管是哪一张,它只是第一张显示在大版本中的图片。但是当我检查源代码时,会为每个图片的大版本调用相关图片。
下面是我用来制作灯箱效果的代码:

<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'post_mime_type'=> 'image',
'orderby'   => 'ID',
'order'     => 'ASC',
);
$attachments = get_posts( $args );
?>
<div class="nine columns">
<div class="about">
<h2><?php the_title(); ?></h2>
<?php  foreach ( $attachments as $attachment ) :
$attachments = get_posts( $args );
$small_image = wp_get_attachment_image_src($attachment->ID, 'thumbnail');
$large_image = wp_get_attachment_image_src($attachment->ID, 'full');
?>
<a href="#<?php echo $attachments ?>"><img src="<?php echo $small_image[0]; >" alt="small"></a> 
<a href="#" id="<?php echo $attachments ?>" class="pressbox"><img src="<?php echo $large_image[0]; ?>" alt="large"></a>
<?php endforeach ?>
</div>
</div> 

提前感谢您调查我的请求 致以亲切的问候
漫游者

您的代码有三个问题:
1.不应调用$attachments=get_posts($args);在foreach中
2.小图像链接的href不正确
3.大图像链接的id不正确

试试这个:

<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'post_mime_type'=> 'image',
'orderby'   => 'ID',
'order'     => 'ASC',
);
$attachments = get_posts( $args );
?>
<div class="nine columns">
<div class="about">
<h2><?php the_title(); ?></h2>
<?php  foreach ( $attachments as $attachment ) :

$small_image = wp_get_attachment_image_src($attachment->ID, 'thumbnail');
$large_image = wp_get_attachment_image_src($attachment->ID, 'full');
?>
<a href="#<?php echo $attachment->ID ?>"><img src="<?php echo $small_image[0]; ?>" alt="small"></a> 
<a href="#" id="<?php echo $attachment->ID ?>" class="pressbox"><img src="<?php echo $large_image[0]; ?>" alt="large"></a>
<?php endforeach ?>
</div>
</div>

您正在编辑什么文件?你能提供一个链接到你的页面吗?