自定义帖子类型single.php中下一个/上一个链接的缩略图

时间:2012-02-13 作者:Meko6

我已经成功地使用以下代码显示了next&;的缩略图;以前的链接用于普通帖子,但这对于自定义帖子类型根本不起作用。

<div id="cooler-nav" class="navigation">
                <?php $prevPost = get_previous_post(true);
                if($prevPost) {?>
                <div class="nav-box previous">
                    <?php $prevthumbnail = get_the_post_thumbnail($prevPost->ID, \'tiny_thumb\' );?>
                    <?php previous_post_link(\'%link\',"$prevthumbnail  <p>%title</p>", TRUE); ?>
                </div>

                <?php } $nextPost = get_next_post(true);
                if($nextPost) { ?>
                <div class="nav-box next">
                    <?php $nextthumbnail = get_the_post_thumbnail($nextPost->ID, \'tiny_thumb\' ); } ?>
                    <?php next_post_link(\'%link\',"$nextthumbnail  <p>%title</p>", TRUE); ?>
                </div>
                <?php  ?>
            </div><!--#cooler-nav div -->
我猜这一定是一个特殊的查询来查找我的自定义帖子类型“公文包”

任何帮助都将不胜感激

编辑

<nav class="clearer">

                <?php if( $prev_post = get_previous_post() ): ?>
                    <?php echo $prev_post->ID ?>
                <div class="nav-box previous">
                    <?php $prevthumbnail = get_the_post_thumbnail($prev_post->ID, \'tiny_thumb\' );?>
                    <?php previous_post_link(\'%link\',"$prevthumbnail  <p>%title</p>", TRUE); ?>
                </div>
                <?php endif; ?>

                <?php if( $next_post = get_next_post() ): ?>
                    <?php echo $next_post->ID ?>
                    <div class="nav-box next">
                        <?php $nextthumbnail = get_the_post_thumbnail($next_post->ID, \'tiny_thumb\' );  ?>
                        <?php next_post_link(\'%link\',"$nextthumbnail  <p>%title</p>", TRUE); ?>
                    </div>
                <?php endif; ?>

            </nav>
其他循环不起作用(我得到缩略图和链接,但不排除当前帖子或随机排序)
<?php   
                    $t_args = array (
                       \'tax_query\' => array (
                          array (
                            \'orderby\' => \'rand\',
                            \'post_type\' => \'portfolio\',
                            \'taxonomy\' => \'service\',
                            \'field\' => \'slug\',
                            \'terms\' => $service_type,
                            \'post__not_in\' => array($post->ID)

                          )
                       )
                    );

                    $query = new WP_Query( $t_args );

                    if( $query->have_posts() ) {
                       while ( $query->have_posts() ) : $query->the_post();

                          // output your stuff
                          echo \'<div class="more_from_thumb"><a href="\';
                          the_permalink();
                          echo \'">\';
                          the_post_thumbnail();
                          echo \'</a></div>\';
                       endwhile;
                       wp_reset_query();
                    } ?>

1 个回复
SO网友:chrisguitarguy

第一个论点是get_previous_postget_next_post$in_same_cat. WordPress正在当前帖子类别中查找相同类型的帖子。如果您的自定义帖子类型不支持category 在分类法中,这两个函数可能不会为上一篇文章和下一篇文章返回任何内容。

尝试调用这两个函数,但不带自定义post类型的参数。

<?php if( $prev_post = get_previous_post() ): ?>
    <div class="nav-box previous">
        <?php $prevthumbnail = get_the_post_thumbnail($prev_post->ID, \'tiny_thumb\' );?>
        <?php previous_post_link(\'%link\',"$prevthumbnail  <p>%title</p>", TRUE); ?>
    </div>
<?php endif; ?>

<?php if( $next_post = get_next_post() ): ?>
    <div class="nav-box next">
        <?php $nextthumbnail = get_the_post_thumbnail($next_post->ID, \'tiny_thumb\' ); } ?>
        <?php next_post_link(\'%link\',"$nextthumbnail  <p>%title</p>", TRUE); ?>
    </div>
<?php endif; ?>

结束

相关推荐

Double thumbnails?

是否可以使用缩略图机制两次?我发现缩略图API非常有用,它允许用户在其中放置自己的图形,以便我可以轻松控制大小和位置。他们所要做的就是记住点击特色图片。我想在我的页面上有两个这样的机制,你知道我该怎么做吗?最好是手工编码。