title: Loop Portfolio Next/Previous Button in Wordpress
body: <p>I am new in php, so I like to get some help.</p>
  
  <p>My clients want the next and previous button to be looped in the single page portfolio. Well this is the code I am using.</p>
  
  <pre><code>&lt;?php
  $prev_post = get_previous_post();
  $next_post = get_next_post();
  $prev_post_link = !empty($prev_post) ? get_permalink($prev_post-&gt;ID) : true;
  $next_post_link = !empty($next_post) ? get_permalink($next_post-&gt;ID) : true;
  if(!empty($prev_post) &amp;&amp; empty($prev_post_thumb)) $prev_post_thumb = prev_next_post_format_icon($prev_post-&gt;ID);
  if(!empty($next_post) &amp;&amp; empty($next_post_thumb)) $next_post_thumb = prev_next_post_format_icon($next_post-&gt;ID);
  ?&gt;
  </code></pre>
  
  <p>When I use True, for both the Previous &amp; Next Links, Its appearing in the first and last portfolio, but the hyperlink is showing as <a href="http://1">http://1</a> and not the next portfolio. Thanks in Advance</p>
  
  <p>This my html code:</p>
  
  <pre><code>&lt;div class="dfd-controls mobile-hide"&gt;
  &lt;?php if(!empty($prev_post_link)) : ?&gt;
      &lt;a href="&lt;?php echo esc_url($prev_post_link); ?&gt;" class="page-inner-nav nav-prev"&gt;
          &lt;div class="dfd-controler prev"&gt;
          &lt;div style="margin-top:7px; color:#fff;"&gt;Previous&lt;/div&gt;
              &lt;!-- &lt;div class="thumb prev"&gt; 
                  &lt;?php echo $prev_post_thumb; ?&gt;
              &lt;/div&gt; --&gt;
          &lt;/div&gt;
          &lt;!--&lt;div class="pagination-title"&gt;Previous Project&lt;/div&gt; --&gt;
      &lt;/a&gt;
  &lt;?php endif; ?&gt;
  &lt;?php if(!empty($next_post_link)) : ?&gt;
      &lt;a href="&lt;?php echo esc_url($next_post_link); ?&gt;" class="page-inner-nav nav-next"&gt;
          &lt;div class="dfd-controler next"&gt;
              &lt;div style="margin-top:7px; color:#fff;"&gt;Next&lt;/div&gt;
              &lt;!-- &lt;div class="thumb next"&gt;
                  &lt;?php echo $next_post_thumb; ?&gt;
              &lt;/div&gt;--&gt;
          &lt;/div&gt;
          &lt;!--&lt;div class="pagination-title"&gt;Next Project&lt;/div&gt;--&gt;
      &lt;/a&gt;
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <p></p>