WP - 发布图像作为下一个帖子页面的链接

时间:2013-12-20 10:17:24

标签: php wordpress image hyperlink next

我使用wordpress和二十二个孩子作为我的主题。 我创建了一个有趣的图片网站,基本上我想要的是每个页面内的图像,就像下一个图像的链接。下面是一些具有此功能的示例网站:DailyHaHaMeme-lol.com您会看到是否点击了图片,它会转到下一个图片页面。我正在使用本地机器,所以我无法链接到我的网站。这是我的content.php:

<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 个答案:

答案 0 :(得分: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>