How to add next and previous post in WordPress?

How to add next and previous post in WordPress? Code for next and previous post in single page, Code for next & previous post in WordPress, PHP code for next & previous post in WordPress. You want to add next and previous post in your single post page, just follow my instruction, from here you can easily get your solution. Here we work single.php and style.css file. Now you open this two file and copy below code and paste to your file. Now copy below code and paste your single.php file where you see your next and previous post.


<div class="next-previous-post">

<?php $BRprevPost = get_previous_post(true);
if($BRprevPost) {
$args = array(
'posts_per_page' => 1,
'include' => $BRprevPost->ID
);
$BRprevPost = get_posts($args);
foreach ($BRprevPost as $post) {
setup_postdata($post);
?>
<?php $embaded_link= get_post_meta($post->ID, 'embaded_link', true); ?>

<div class="brnewstheme-previous-post">
<h3 class="sidebar-title"><a class="previous-link" href="<?php the_permalink(); ?>">&laquo; Previous Article</a></h3>
<?php if ( has_post_thumbnail() ) : ?>
<div class="post-thumbs">
<div class="img-box">
<img src="<?php the_post_thumbnail_url('medium'); ?>"/>
<div class="ovrly"></div>
<div class="buttons">
<a class="fa fa-search info" href="<?php the_post_thumbnail_url(); ?>" rel="prettyPhoto" title="<?php the_title_attribute(); ?>"></a>

</div>
</div>
</div>
<?php elseif((meta_options('pagebg') !='' || meta_options('embaded_link')!='')): ?>
<div class="video-post">
<?php echo emabdedTheLink(meta_options('embaded_link'),'130','85'); //with width(1000,500);?>
<div class="ovrly"></div>
<div class="buttons">
<a class="fa fa-search info" href="<?php echo $embaded_link; ?>" rel="prettyPhoto" title="<?php the_title_attribute(); ?>"></a>

</div>
</div>
<?php else : ?>
<div class="post-thumbs">
<div class="img-box">
<img src="<?php bloginfo('template_url'); ?>/images/it-helps-bd.jpg" alt="" />
<div class="ovrly"></div>
<div class="buttons">
<a class="fa fa-search info" href="<?php echo bloginfo('template_url'); ?>/images/it-helps-bd.jpg" rel="prettyPhoto" title="<?php the_title_attribute(); ?>"></a>
</div>
</div>
</div>
<?php endif; ?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<div class="meta-post">
<div class="meta-data date"><?php the_time('F j, Y') ?></div>
<div class="meta-data post-author"><?php the_author(); ?></div>

</div>
</div>
<?php
wp_reset_postdata();
}
}

$BRnextPost = get_next_post(true);
if($BRnextPost) {
$args = array(
'posts_per_page' => 1,
'include' => $BRnextPost->ID
);
$BRnextPost = get_posts($args);
foreach ($BRnextPost as $post) {
setup_postdata($post);
?>
<?php $embaded_link= get_post_meta($post->ID, 'embaded_link', true); ?>

<div class="brnewstheme-next-post">
<h3 class="sidebar-title"><a class="next-link" href="<?php the_permalink(); ?>">Next Article &raquo;</a></h3>
<?php if ( has_post_thumbnail() ) : ?>
<div class="post-thumbs">
<div class="img-box">
<img src="<?php the_post_thumbnail_url('medium'); ?>"/>
<div class="ovrly"></div>
<div class="buttons">
<a class="fa fa-search info" href="<?php the_post_thumbnail_url(); ?>" rel="prettyPhoto" title="<?php the_title_attribute(); ?>"></a>

</div>
</div>
</div>
<?php elseif((meta_options('pagebg') !='' || meta_options('embaded_link')!='')): ?>
<div class="video-post">
<?php echo emabdedTheLink(meta_options('embaded_link'),'130','85'); //with width(1000,500);?>
<div class="ovrly"></div>
<div class="buttons">
<a class="fa fa-search info" href="<?php echo $embaded_link; ?>" rel="prettyPhoto" title="<?php the_title_attribute(); ?>"></a>

</div>
</div>
<?php else : ?>
<div class="post-thumbs">
<div class="img-box">
<img src="<?php bloginfo('template_url'); ?>/images/it-helps-bd.jpg" alt="" />
<div class="ovrly"></div>
<div class="buttons">
<a class="fa fa-search info" href="<?php echo bloginfo('template_url'); ?>/images/it-helps-bd.jpg" rel="prettyPhoto" title="<?php the_title_attribute(); ?>"></a>
</div>
</div>
</div>
<?php endif; ?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<div class="meta-post">
<div class="meta-data date"><?php the_time('F j, Y') ?></div>
<div class="meta-data post-author"><?php the_author(); ?></div>

</div>
</div>
<?php
wp_reset_postdata();
}
}
?>
</div>

Now you open your style.css file and copy below code and paste to your style.css file.


/* PREVIOUS POST AND NEXT POST IN SINGLE.PHP*/
.next-previous-post{ margin-top:20px;}
.brnewstheme-previous-post, .brnewstheme-next-post{ display:inline-block; width:48%; margin-right:3%; margin-bottom:20px;}
.brnewstheme-next-post{ margin-right:0%;}
.brnewstheme-previous-post .post-thumbs .img-box, .brnewstheme-next-post .post-thumbs .img-box, .brnewstheme-next-post .video-post{ width:30%; max-width:100%;}
.next-previous-post .post-thumbs .buttons .fa, .brnewstheme-next-post .post-thumbs .buttons .fa, .next-previous-post .video-post .buttons .fa{ line-height:30px; width:30px; height:30px;}

24 Responses to “How to add next and previous post in WordPress?”

  1. Mersin parça eşya taşıma hizmetini her zaman vermek için hazır dayız parça eşya taşıma da gücümüzün yetmediği başınızın sıkıştığı yerde bizim öncü firmalarımız gelir sizler için her zaman en iyi kaliteyi sunmaya çalışıyoruz. Mersin parça eşya taşıma fiyatları ve parsiyel taşımacılık için en uygun fiyat politikaları sizleri bekliyor.

  2. viz says:

    Say, you got a nice blog post.Thanks Again.

  3. viz says:

    A big thank you for your blog article.Thanks Again. Want more.

  4. I have wanted to post something like this on one of my blogs and this has given me an idea. Thank you.

  5. 19 yas porno says:

    Say, you got a nice blog post.Thanks Again.

  6. Bez çanta satışı toptan ve perakende amerikan bezinden imalat yapılmış bez çantalar promosyon çanta. https://uniwaybezcanta.com/bez-canta/ #BezÇanta Bez Çanta ürünlerinde online satış GittiGidiyor’da! Bez Çanta modelleri, Bez Çanta çeşitleri ve markalarını uygun fiyatları ile satın alın.

  7. Whoa! This blog looks just like my old one! It’s on a entirely different subjecct but it has pretty
    much the same pawge layout and design. Excellent cholice of colors!

  8. It is nott myy first time to visiot this website, i am
    browsing this weeb page dailly and get nice facts
    from here daily.

  9. pornom says:

    Thank you for your blog article.Really looking forward to read more. Will read on…

  10. pornom says:

    Say, you got a nice blog post.Thanks Again.

  11. Web Tasarım, Grimor, kuruluşundan beri sizlere özel tasarım ve web hizmetleri vermektedir. https://www.pentayazilim.com/web-tasarim/ Web tasarım ihtiyaçlarınız için en doğru adres Grimor.com. Kurumsal web tasarım firması MediaClick İstanbul, SEO ve mobil uyumlu profesyonel web site tasarımları ile web sitesi tasarımı yarışmalarında ödüller almıştır. Profesyonel web tasarım hizmetleri sunan, Biltek Web Tasarım şirketi ile kusursuz bir web sitesi tasarımına sahip olacaksınız. Web Tasarım ajansımız İstanbul’da…

  12. sex izle says:

    I cannot thank you enough for the post.Really looking forward to read more. Cool.

  13. cocuk porno says:

    Thank you for your blog article.Really looking forward to read more. Will read on…

  14. Hosting Games 2018 Yılında Hosting Games İnternet Hizmetleri tarafından kurulmuştur.Kesintisiz ve kaliteli hizmetler vererek müşterilerinin arzularını yerine getirmeye çalışmaktayız,uzman kadromuz ve son teknoloji makinelerimiz ile en iyi hizmeti vermeye çalışmaktayız.Kendine ait alt yapı yatırımı sayesinde her zaman güncel donanımlara sahiptir…!! Website https://hostingames.com/

  15. A big thank you for your blog article.Thanks Again. Want more.

  16. Say, you got a nice blog post.Thanks Again.

  17. Carl Feehan says:

    Hello my friend! I want to say that this article is amazing, nice written and come with almost all important infos. I’d like to look more posts like this .

  18. I cannot thank you enough for the post.Really looking forward to read more. Cool.

  19. Greetings! I’ve been following your weblog for a long time now and finally got the courage to go ahead and give you a shout out from Lubbock Tx! Just wanted to tell you keep up the great work!

  20. BLONDO HOLDINGS is a private investment company incorporated in the United Kingdom. Our team consists of professionals who provide clients and partners with confidence and only best consulting and financial services. Join our company and use a great chance to conquer the trading market and be successful people. Our company, BLONDO HOLDINGS, is engaged in the cryptocurrencies mining and investments in Blockchain technology as one of the most promising technologies of the 21st century, and achieved high results in own activities. We offer 4 different investment plans: STARTER PLAN: 150 Per Cent Weekly (Min: 10 DOLLARS – Max: 49 DOLLARS) (TOTAL RETURN: 150 per cent) /// SILVER PLAN: 200 Per Cent Weekly (MIN: 50 DOLLARS – MAX: 299 DOLLARS) (TOTAL RETURN: 200 per cent) /// GOLD PLAN: 1 per cent Hourly – Duration: 7 Days – (Min 300 – Max 1000) (TOTAL RETURN: 168 per cent) (Withdrawal Anytime) /// PLATINUM PLAN: 5 per cent Daily – Duration: 55 Days – (Min: 500 – Max: 2500) (TOTAL RETURN: 275 per cent) (Withdrawal Anytime)

  21. I appreciate you sharing this blog article. Much obliged.

  22. I cannot thank you enough for the post.Really looking forward to read more. Cool.

  23. A big thank you for your blog article.Thanks Again. Want more.

  24. google says:

    I appreciate you sharing this blog article. Much obliged.

​Leave a Comment

Comment authors age:




How to Recent Post Show Exclude a Specific Taxonomy?

How to add related post in wordpress?