gpt4 book ai didi

javascript - 在模态内的wordpress帖子中添加下一个和上一个按钮

转载 作者:行者123 更新时间:2023-11-29 21:52:25 25 4
gpt4 key购买 nike

我使用 bootstrap 框架创建了一个 wordpress 主题,当用户点击一个帖子时,不会转到单个帖子页面,而是弹出模态并显示帖子的内容。

我的问题是我需要添加一个下一个/上一个按钮,这样当用户点击它时,模态关闭并弹出另一个显示下一篇文章内容的模态。

这是我的代码:

content.php

<a href="#myModal-<?php the_ID(); ?>" data-toggle="modal" class="clickme readmore text-right">Read more</a>

<div id="myModal-<?php the_ID(); ?>" class="modal fade"><?php include 'popup-modal.php'; ?> </div>

popup-modal.php

<div class="modal-dialog">
<div class="modal-content">

POST CONTENT HERE.......

<div class="nav-links">
<div class="nav-previous">
<a href="#" rel="prev" data-dismiss="modal" data-toggle="modal"></a>
</div>
<div class="nav-next">
<a href="#" rel="next" data-dismiss="modal" data-toggle="modal"></a>
</div>
</div>

</div>
</div>

现在我不确定在导航链接的 href 上放什么,所以我可以调用下一篇文章并将其显示在模态中。我希望有人能帮我解决这个问题。

最佳答案

这是我的解决方案:

<?php $next_post = get_adjacent_post(false,'',false);?>
<?php $previous_post = get_adjacent_post(false,'',true);?>

然后是导航输出:

<div class="navigation row">
<div class="col-md-6">
<?php if($next_post->ID != ''): ?>
<a href="#myModal-<?php echo $next_post->ID; ?>" data-toggle="modal" >
<button type="button" class="btn btn-default m-t-30">Previous</button>
</a>
<?php endif; ?>
</div>
<div class="col-md-6">
<?php if($previous_post->ID != ''): ?>
<a href="#myModal-<?php echo $previous_post->ID; ?>" data-toggle="modal" >
<button type="button" class="btn btn-default m-t-30">Next</button>
</a>
<?php endif; ?>
</div>

关于javascript - 在模态内的wordpress帖子中添加下一个和上一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28404416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com