2013-12-20 72 views
0

我使用wordpress和二十二個孩子作爲我的主題。 我做了一個有趣的圖片網站,基本上我想要的是每個頁面內的圖像就像一個鏈接到下一個圖像。下面是一些使用此功能的示例網站:DailyHaHaMeme-lol.com您會看到如果單擊圖像,它會將您帶到下一圖像頁面。我在本地機器上工作,所以我不能鏈接到我的網站。這裏是我的content.php:WP - 發佈圖片作爲下一篇文章的鏈接

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
    <?php if (is_sticky() && is_home() && ! is_paged()) : ?> 
    <div class="featured-post"> 
     <?php _e('Featured post', 'twentytwelve'); ?> 
    </div> 
    <?php endif; ?> 
    <div class="entry-header"> 
     <?php the_post_thumbnail(); ?> 
     <?php if (is_single()) : ?> 
     <div class="post-header"> 
     <div class="entry-title"> 
      <a href="#comment" rel="bookmark"><?php the_title(); ?></a> 
     </div> 
     <span class="inline-div"> 
     <span class="entry-bar"><li><?php echo "Added "; wp_days_ago(); ?></li> </span> 

       <li><?php comments_popup_link('<span class="leave-reply">' . __('Be first to comment', 'twentytwelve') . '</span>', __('1 comment', 'twentytwelve'), __('% comments', 'twentytwelve')); ?></li> 
      <!-- .comments-link --> 
      <span class="edit"><li><?php edit_post_link(__('Edit', 'twentytwelve'), '<span class="edit-link">', '</span>'); ?></li></span> 
     </span> 

     <?php else : ?> 

     <div class="entry-title"> 
      <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a> 
     </div> 
     <span class="inline-div"> 
     <span class="entry-bar"><li><?php echo "Added "; wp_days_ago(); ?></li> </span> 

       <li><?php comments_popup_link('<span class="leave-reply">' . __('Be first to comment', 'twentytwelve') . '</span>', __('1 comment', 'twentytwelve'), __('% comments', 'twentytwelve')); ?></li> 
      <!-- .comments-link --> 
      <span class="edit"><li><?php edit_post_link(__('Edit', 'twentytwelve'), '<span class="edit-link">', '</span>'); ?></li></span> 
     </span> 

     <?php endif; // is_single() ?> 
    </div><!-- .entry-header --> 

    <?php if (is_search()) : // Only display Excerpts for Search ?> 
    <div class="entry-summary"> 
     <?php the_excerpt(); ?> 
    </div><!-- .entry-summary --> 
    <?php else : ?> 

    <div class="entry-content"> 
     <?php the_content(__('Continue reading <span class="meta-nav">&rarr;</span>', 'twentytwelve')); ?> 
     <?php wp_link_pages(array('before' => '<div class="page-links">' . __('Pages:', 'twentytwelve'), 'after' => '</div>')); ?> 
    </div><!-- .entry-content --> 

    <?php endif; ?> 
    <div class="share-buttons"> 
    <a class="facebook-button" target="_blank" onclick="return !window.open(this.href, 'Facebook', 'width=640,height=300')" href="http://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>"><img src="/images/share.png" /></a> 
      <a class="tweet-button" target="_blank" href="http://twitter.com/share"><img src="/images/tweet.png" /></a> 

    </div> 
    <div class="nav2"> 

    <span class="previous-button"> 
       <?php next_post_link('%link', '<img src="/images/prev.png" alt="Previous"/>'); ?> 
       </span> 

    <span class="random-post"> 
       <?php $randomPost = $wpdb->get_var("SELECT guid FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY rand() LIMIT 1"); 
       echo '<a href="'.$randomPost.'"><img src="/images/random.png" alt="Random"/></a>'; ?> 
       </span> 

       <span class="next-button"> 
       <?php previous_post_link('%link', '<img src="/images/Next.png" alt="Next"/>'); ?> 
       </div> 

       <br /> 
       </span> 
</article><!-- #post --> 

回答

1

您需要先獲得該帖子的精選圖片。

<?php // Display the thumbnail of the previous post ?> 
    <span class="previous-button"> <?php 
     $prevPost = get_previous_post(); 
     $prevthumbnail = get_the_post_thumbnail($prevPost->ID); ?> 
     <?php previous_post_link('%link', $prevthumbnail); ?> 
    </span> 

<?php // Display the thumbnail of the next post ?> 
    <span class="next-button"> <?php 
     $nextPost = get_next_post(); 
     $nextthumbnail = get_the_post_thumbnail($nextPost->ID); ?> 
     <?php next_post_link('%link', $nextthumbnail); ?> 
    </span> 
相關問題