2012-11-16 64 views
0

我目前的WordPress主题有一个内置的画廊。每个图库显示第一个/主要缩略图,并且一旦点击,即可在shadowbox中打开该特定图库的全部内容。我现在的理想目标是找到一种方法来改变这种情况,而不是直接显示shadowbox,而是直接指向具有特定画廊内容的单个页面。单个页面上的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; ?>&amp;w=270&amp;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

哪个WordPress主题?这有助于了解可能的解决方案。谢谢。 – donlaur

+0

主题被称为“le美食家” –

回答

2

使用wp_get_attachment_link($id, $size, $permalink, $icon, $text);(参见http://codex.wordpress.org/Function_Reference/wp_get_attachment_link)。这会将链接输出到附件页面。所以你只需要用这个函数来调整你的代码。对$ permalink参数使用value = 0,以便链接将您带到附件页面(value = 1会将您带到文件本身)。 但是,请注意,“shadowbox”可能是由JavaScript中的事件绑定(单击锚点)触发的,因此您可能必须修改HTML代码以获取链接。如果shadowbox脚本中的选择器使用类名称或ID来检测点击,则可能需要更改链接容器的ID或类名称,以确保目标页面不会显示在shadowbox内。 考虑到在本页中不需要它,您还可以(实际上)使用wp_deregister_script()来取消注册显示shadowbox的脚本。

+0

非常感谢您的见解 - 一定会看看它 –