【问题标题】:WP - Post images as a link to next post pageWP - 将图像作为指向下一个帖子页面的链接发布
【发布时间】:2014-01-09 04:16:22
【问题描述】:

我使用 wordpress 和 22 个孩子作为我的主题。 我为有趣的图片创建了一个网站,基本上我想要的是每个页面内的图片,就像指向下一张图片的链接一样。下面是一些具有此功能的示例站点: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 -->

【问题讨论】:

    标签: php wordpress image hyperlink next


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 2014-05-07
      • 2013-04-24
      • 1970-01-01
      • 1970-01-01
      • 2013-08-11
      • 2014-06-27
      • 1970-01-01
      • 2013-05-19
      • 1970-01-01
      相关资源
      最近更新 更多