打开链接页面而不是fancybox

时间:2014-05-20 07:36:08

标签: php fancybox

我有一个用于图库的代码。此图库中的图像在fancybox中打开。我不想将此图像链接到fancybox但我想将此图像链接到一个特定页面。这是必须自定义的代码:

<?php

global $sr_prefix;

$gallery = get_post_meta($post->ID, $sr_prefix.'_medias', true);
$postid = $post->ID;

$maintitle = 'h2'; $subtitle = 'h5';
if (get_option($sr_prefix.'_blogentrieslayout') == 'masonry' || get_option($sr_prefix.'_blogentrieslayout') == 'bloglist') { $maintitle = 'h4'; $subtitle = 'h6'; }

if( empty($gallery) || get_option($sr_prefix.'_blogentriesdisplay') == 'featuredimage' || get_option($sr_prefix.'_blogpostgallerydisplay') == "list" ) {
?>  

<?php if(has_post_thumbnail()) { ?>
    <div class="entry-thumb entry-media blog-media">
        <div class="imgoverlay">
            <a href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail('single-blog-image'); ?>
                <div class="overlay"><span class="overlaycolor"></span><span class="overlayinfo">
                    <?php echo '<'.$maintitle.'>'; ?><strong><?php the_title(); ?></strong><?php echo '</'.$maintitle.'>'; ?>
                    <?php if (!get_option($sr_prefix.'_blogpostsdisabledate')) { ?>
                    <?php echo '<'.$subtitle.'>'; ?><?php the_time(get_option('date_format')); ?><?php echo '</'.$subtitle.'>'; ?>
                    <?php } ?>
                </span></div>
            </a>
        </div>
    </div> <!-- END .entry-media -->
<?php } ?>

<?php   
} else {    

$medias = explode('|||', $gallery);

$output_medias = '';
foreach ($medias as $media) {
    $object = explode('~~', $media);
    $type = $object[0];
    $val = $object[1];
    $output_medias .= "<li>"; 
    if ($type == 'image') { 
        $image = wp_get_attachment_image_src($val, 'single-blog-image'); $image = $image[0];
        $fancyimage = wp_get_attachment_image_src($val, 'full'); $fancyimage = $fancyimage[0];
        $thisimage = '<img src="'.$image.'" alt="'.get_the_title($image[1]).'"/>';
        if(get_option($sr_prefix.'_blogpostsdisablefancybox') !== "on") {
            $output_medias .= '<div class="imgoverlay"><a href="'.$fancyimage.'" class="openfancybox" rel="gallery'.get_the_ID().'" title="'.get_the_title($image[1]).'">'.$thisimage.'<div class="overlay"><span class="overlaycolor"></span></div></a></div>';
        } else {
            $output_medias .= $thisimage;
        }
    } else {
        $output_medias .= '<div class="embeddedvideo">'.$val.'</div>';
    }
    $output_medias .= "</li>";
}

?>
    <?php if(get_option($sr_prefix.'_blogpostgallerydisplay') !== "list" ) {  ?>
    <div class="entry-media blog-media">
        <div id="slider-<?php echo $postid; ?>" class="flexslider-container post-slider">        
            <div class="flexslider">
                <ul class="slides">
                    <?php echo $output_medias; ?>                
                </ul>
            </div>
        </div>
    </div> <!-- END .entry-media -->
    <?php } else { ?>
    <div class="entry-media blog-media">
        <?php the_post_thumbnail('single-blog-image'); ?>
    </div> <!-- END .entry-media -->
    <?php } ?>

<?php } ?>

1 个答案:

答案 0 :(得分:0)

好像你正在使用Wordpress。

首先,你必须看看这部分

if ($type == 'image') { 
        $image = wp_get_attachment_image_src($val, 'single-blog-image'); $image = $image[0];
        $fancyimage = wp_get_attachment_image_src($val, 'full'); $fancyimage = $fancyimage[0];
        $thisimage = '<img src="'.$image.'" alt="'.get_the_title($image[1]).'"/>';
        if(get_option($sr_prefix.'_blogpostsdisablefancybox') !== "on") {
            $output_medias .= '<div class="imgoverlay"><a href="'.$fancyimage.'" class="openfancybox" rel="gallery'.get_the_ID().'" title="'.get_the_title($image[1]).'">'.$thisimage.'<div class="overlay"><span class="overlaycolor"></span></div></a></div>';

您有if(get_option($sr_prefix.'_blogpostsdisablefancybox') !== "on")选项,我认为可以禁用fancybox,也许它位于WP管理面板中。

无论如何,如果我没记错的话,fancybox会将它的事件链接到特定的类,在这种情况下它是openfancybox类。您可以删除此类并禁用fancybox。

$output_medias .= 
'<div class="imgoverlay">
<a href="'.$fancyimage.'" class="openfancybox" rel="gallery'.get_the_ID().'" title="'.get_the_title($image[1]).'">'.$thisimage.'
<div class="overlay"><span class="overlaycolor">
</span>
</div>
</a>
</div>';

然后你可以将$ fancyimage变量更改为你想要的URL。