2015-02-09 56 views
2

我使用引導框架創建了wordpress主題,當用戶點擊帖子而不是轉到單個帖子頁面時,模塊彈出並顯示帖子的內容。在模態內添加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,以便我可以調用下一篇文章並在模態中顯示它。我希望有人能幫助我解決這個問題。

回答

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> 

0

嘗試這樣的事情

<div class="next-page"><?php next_posts_link('Next Page<i class=""></i>'); ?></div> 
我在自己的網站上使用這個

,我希望它你需要什麼。您將需要直接將它添加到您的模板

+0

沒有這一項,我需要它在模式內部,以便當用戶點擊它時,模式關閉,另一個與下一個帖子的內容一起彈出。 – deedee92 2015-02-09 08:08:40

+0

你可以在模態中添加這個。但我通常會使用帶有引導程序按鈕樣式的「」標記。在那裏你可以輸出類似#myMidal - <?php echo get_the_ID() - 1; ?>(或geht_the_ID()+ 1) – jankal 2015-02-10 13:01:55

相關問題