链接到自定义查询中的较大缩略图(带有自定义帖子类型)

时间:2011-08-12 作者:juliusk

我正在使用带有自定义帖子类型的自定义查询来显示我兄弟摄影网站的博客存档。I集成this code 链接到缩略图的较大版本。遗憾的是,它不起作用。是因为它是一个自定义查询吗?

<?php /*
Template Name: Archiv
*/ ?>
<?php get_header(); ?>

    <section id="content">
        <div id="archive">
            <?php $args = array( 
                \'post_type\' => array(\'blog\'), 
                \'numberposts\' => -1, 
                \'post_status\' => null, 
                \'post_parent\' => null,
                ); 
                $posts = get_posts($args);  ?>

            <?php if ($posts) { 
                foreach ($posts as $post) { 
                    setup_postdata($post); 
                    $month =  mysql2date(\'F Y\', $post->post_date); 
                    if ($month != $check) {                 } 
                $check = $month; ?>




                    <div class="einzelbild einzelbild-<?php the_ID(); ?>">
                    <a href="<?php $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "medium" ); ?>"><?php the_post_thumbnail(\'medium\'); ?></a>
                    <a href="<?php $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "medium" ); ?>" class="linkbox-<?php the_ID(); ?> linkbox" style="display:none;"><span class="datum"><?php the_date(\'M jS\'); ?></span><br /><h1 class="post-title"><?php the_title(); ?></h1>
                    </a>
                    </div>

                    <script type="text/javascript">
                        $(document).ready(function() {
                            var hide = false;
                            $(".einzelbild-<?php the_ID(); ?>").hover(function(){
                                if (hide) clearTimeout(hide);
                                $(".linkbox-<?php the_ID(); ?>").fadeIn();
                            }, function() {
                                hide = setTimeout(function() {$(".linkbox-<?php the_ID(); ?>").fadeOut(500);}, 100);
                            });
                            $(".linkbox-<?php the_ID(); ?>").hover(function(){
                                if (hide) clearTimeout(hide);
                            }, function() {
                                hide = setTimeout(function() {$(".linkbox-<?php the_ID(); ?>").fadeOut(500);}, 100);
                            });
                        });
                    </script> 

            <?php } 
            } 
            ?>  
        </div>
</section> 
<script>
 $(function(){

    var $container = $(\'#archive\');

    $container.imagesLoaded( function(){
      $container.masonry({
        itemSelector : \'.einzelbild\',
        columnWidth: 10,
        isAnimated: true,
          animationOptions: {
            duration: 750,
            easing: \'linear\',
            queue: false
          }
      });
    });

  });</script>


<?php include \'sidebar-blog.php\'; ?>
<?php get_footer(); ?>

1 个回复
最合适的回答,由SO网友:Scott 整理而成

在代码中,您使用以下代码链接到图像:

wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "medium" );
因此,您要做的是显示中等大小的图像以及链接到中等大小的图像。

您需要做的是链接到全尺寸图像:

wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full" );
还有wp_get_attachment_image_src 返回以下内容:

array
(
[0] => url
[1] => width
[2] => height
)
因此:

<a href="<?php $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "medium" ); ?>"><?php the_post_thumbnail(\'medium\'); ?></a>
需要成为:

<?php
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full" );
?>
<a href="<?php echo $thumbnail_src[0]; ?>"><?php the_post_thumbnail(\'medium\'); ?></a>

结束

相关推荐