我目前的WordPress主题有一个内置画廊。每个图库都显示第一个/主缩略图,一旦点击,就会在阴影框中打开此特定图库的全部内容。我现在的理想目标是找到一种方法来改变它,而不是直接显示影子框,而是指向具有特定图库内容的单个页面。
如下我目前的图库代码:
<div id="maincontentwrap">
<div class="main-sep">
</div><!-- .main-sep -->
<div id="contentwrap">
<div id="content-gallery" role="main">
<?php
$wp_query = new WP_Query();
$wp_query->query( array( 'post_type' => 'galleries', 'posts_per_page' => of_get_option('le_gallery_items'), 'paged' => $paged, 'orderby' => 'menu_order', 'order' => 'ASC') );
$mod = 1;
while ( $wp_query->have_posts() ) : $wp_query->the_post();
$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order') );
if(has_post_thumbnail()) {
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
$src = $src[0];
}
else{
foreach ( $attachments as $id => $attachment ) {
$src = wp_get_attachment_url( $id );
}
}
if ($mod % 3 == 0) {
echo ' <div class="gallery-entry-img-last">';
}
else{
echo ' <div class="gallery-entry-img">';
}
?>
<div class="gallery-entry-img-l"><a rel="next" href="<?php echo $src; ?>"><span class="rollover" ></span><img class="blog-entry-img" src="<?php echo get_bloginfo('stylesheet_directory'); ?>/library/tools/timthumb.php?src=<?php echo $src; ?>&w=270&h=198" alt="<?php get_the_title(); ?>"/></a>
<span class="gallery-entry-img-tab"></span>
</div>
<span class="gallery-index-title"><?php the_title(); ?></span>
<div class="hidden-gallery">
<?php
$pic_count = 0;
foreach ( $attachments as $id => $attachment ) {
$pic_count++;
$others_src = wp_get_attachment_url( $id );
?>
<a rel="next" href="<?php echo $others_src; ?>" title="<?php the_title(); ?>"></a>
<?php
}
?>
</div><!-- .hidden-gallery-->
</div>
<?php
$mod++;
endwhile;
?>
<div style="clear:both;"></div>
</div>
</div><!-- #contentwrap-->
</div><!-- #maincontentwrap-->
有人知道如何实现这一目标吗?一些专家建议真的很感激。
答案 0 :(得分:2)
使用wp_get_attachment_link( $id, $size, $permalink, $icon, $text );
(请参阅http://codex.wordpress.org/Function_Reference/wp_get_attachment_link)。这会将链接输出到附件页面。因此,您只需要使用此功能调整代码。使用value = 0作为$ permalink参数,这样您的链接就会将您带到附件页面(value = 1会将您带到文件本身)。
但要注意,“shadowbox”可能是由JavaScript中的事件绑定(单击锚点)触发的,因此您可能需要调整链接的HTML代码。如果shadowbox脚本中的选择器使用类名或ID来检测单击,则可能需要更改链接容器的ID或类名,以确保不会显示目标页面在影子箱内。
您也可以(并且应该,实际上)使用wp_deregister_script()
取消注册显示阴影框的脚本,考虑到您在此页面中不需要它。