2013-07-12 84 views
0

我最近嘗試了上一篇文章和下一篇文章按鈕鏈接。我這樣做與工作perfect.But的site.Its的左側和右側圖像我不知道如何做到這一點Next Previous Post in wordpress with previous/next link with title?

例如:

<div class="alignleftfp"> 
         <?php next_post('%', '<img class="imgalign" src="' . WP_CONTENT_URL . '/uploads/1.png" alt="Next" /> ', 'no'); 
         ?> 
        </div> 
        <div class="alignrightfp"> 

         <?php previous_post('%', '<img class="imgalign" src="' . WP_CONTENT_URL . '/uploads/1.png" alt="Next" /> ', 'no'); 
         ?> 
        </div> 

是否有可能顯示上一篇文章和下篇文章鏈接與帖子底部的標題。這是截圖。 enter image description here

+1

嗨,維基我添加的代碼只顯示下一個以前的帖子標題與鏈接,所以自定義和添加圖像爲下一個以前。 –

回答

2
<nav id="nav-single"> 
    <?php 
     $prev_post = get_previous_post(); 
     $id = $prev_post->ID ; 
     $permalink = get_permalink($id); 
    ?> 
    <?php 
     $next_post = get_next_post(); 
     $nid = $next_post->ID ; 
     $permalink = get_permalink($nid); 
    ?> 
     <span class="nav-previous"><?php previous_post_link('%link', __('<span class="meta-nav">&larr;</span> Previous', 'twentyeleven')); ?> 
      <h2><a href="<?php echo $permalink; ?>"><?php echo $prev_post->post_title; ?></a></h2> 
     </span> 

     <span class="nav-next"><?php next_post_link('%link', __('Next <span class="meta-nav">&rarr;</span>', 'twentyeleven')); ?> 
      <h2><a href="<?php echo $permalink; ?>"><?php echo $next_post->post_title; ?></a></h2> 

     </span> 
</nav> 

enter image description here

1

我希望你正在使用從顯示在文章的整體凡在single.php中的代碼。爲了顯示鏈接(Next/Prev),您需要檢查該功能。

get_template_part() 

in the same file (Single.php of your theme). In my case function in single.php has been passes parameters like 

<?php get_template_part('content-single', get_post_format()); ?> 

So, you will open the "content-single.php" according to the parameters specified in the function and paste the same code 

<div class="alignleftfp"> 
<?php next_post('%', '<img class="imgalign" src="' . get_bloginfo('template_directory') . '/images/1.png" alt="Next" /> ', 'no'); 
?> 
</div> 

<?php previous_post('%', '<img class="imgalign" src="' . get_bloginfo('template_directory') . '/images/2.png" alt="Next" /> ', 'no'); 
?> 
</div> 

below <h1 class="entry-title"><?php the_title(); ?></h1> 

我希望這將解決您的問題。

+0

請參閱我嘗試過的示例插件。不編輯任何主題文件 –

+0

對不起如果你混淆我之前添加的標籤('Wordpress主題') –

+0

+1回答 –