我使用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>
弹出-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上,以便我可以调用下一个帖子并将其显示在模态中。我希望有人可以帮我解决这个问题。
答案 0 :(得分:2)
这是我的解决方案:
<?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>
答案 1 :(得分:0)
尝试这样的事情
<div class="next-page"><?php next_posts_link( 'Next Page<i class=""></i>' ); ?></div>
我在自己的网站上使用过这个,我希望它可以满足您的需求。您需要将其直接添加到模板中