循环投资组合下一个/上一个按钮在WordPress


Loop Portfolio Next/Previous Button in Wordpress

我是php的新手,所以我喜欢得到一些帮助。

我的客户希望下一个和上一个按钮在单页投资组合中循环播放。好吧,这是我正在使用的代码。

<?php
$prev_post = get_previous_post();
$next_post = get_next_post();
$prev_post_link = !empty($prev_post) ? get_permalink($prev_post->ID) : true;
$next_post_link = !empty($next_post) ? get_permalink($next_post->ID) : true;
if(!empty($prev_post) && empty($prev_post_thumb)) $prev_post_thumb = prev_next_post_format_icon($prev_post->ID);
if(!empty($next_post) && empty($next_post_thumb)) $next_post_thumb = prev_next_post_format_icon($next_post->ID);
?>

当我使用 True 时,对于上一个和下一个链接,它出现在第一个和最后一个投资组合中,但超链接显示为 http://1 而不是下一个投资组合。提前致谢

这是我的 html 代码:

<div class="dfd-controls mobile-hide">
<?php if(!empty($prev_post_link)) : ?>
    <a href="<?php echo esc_url($prev_post_link); ?>" class="page-inner-nav nav-prev">
        <div class="dfd-controler prev">
        <div style="margin-top:7px; color:#fff;">Previous</div>
            <!-- <div class="thumb prev"> 
                <?php echo $prev_post_thumb; ?>
            </div> -->
        </div>
        <!--<div class="pagination-title">Previous Project</div> -->
    </a>
<?php endif; ?>
<?php if(!empty($next_post_link)) : ?>
    <a href="<?php echo esc_url($next_post_link); ?>" class="page-inner-nav nav-next">
        <div class="dfd-controler next">
            <div style="margin-top:7px; color:#fff;">Next</div>
            <!-- <div class="thumb next">
                <?php echo $next_post_thumb; ?>
            </div>-->
        </div>
        <!--<div class="pagination-title">Next Project</div>-->
    </a>
<?php endif; ?>

值从 true 更改为 false。将变量设置为 true 将给empty一个 false 值,请参阅此处。

现在"下一个"只会在有下一篇文章时才显示

你的 PHP 应该是:

$prev_post = get_previous_post();
$next_post = get_next_post();
$prev_post_link = !empty($prev_post) ? get_permalink($prev_post->ID) : false;
$next_post_link = !empty($next_post) ? get_permalink($next_post->ID) : false;
if(!empty($prev_post) && empty($prev_post_thumb)) $prev_post_thumb = prev_next_post_format_icon($prev_post->ID);
if(!empty($next_post) && empty($next_post_thumb)) $next_post_thumb = prev_next_post_format_icon($next_post->ID);

更新:要让帖子循环:

if( get_adjacent_post(false, '', true) ) { 
    previous_post_link('%link', '<div class="dfd-controler prev"><div style="margin-top:7px; color:#fff;">Previous</div></div>');
} else { 
    $first = new WP_Query('posts_per_page=1&order=DESC'); $first->the_post();
        echo '<a href="' . get_permalink() . '"><div class="dfd-controler prev"><div style="margin-top:7px; color:#fff;">Previous</div></div></a>';
    wp_reset_query();
}; 
if( get_adjacent_post(false, '', false) ) { 
    next_post_link('%link', '<div class="dfd-controler next"><div style="margin-top:7px; color:#fff;">Next</div></div>');
} else { 
    $last = new WP_Query('posts_per_page=1&order=ASC'); $last->the_post();
        echo '<a href="' . get_permalink() . '"><div class="dfd-controler next"><div style="margin-top:7px; color:#fff;">Next</div></div>';
    wp_reset_query();
};  

Wordpress 中的循环投资组合下一个/上一个按钮

     <div class='next_post_link_align'>
<?php next_post_link('<span class="previous_post_link">&larr; %link </span> <span class="post_link_text">'.__('(previous entry)','avia_framework'))."</span>";?>
</div>   
    <div class='previous_post_link_align'>
<?php previous_post_link('<span class="next_post_link"><span class="post_link_text">'.__('(next entry)','avia_framework').'</span> %link &rarr;</span>'); ?>
</div>