网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > WordPress
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 114.238.3.29
Old 2014-06-01, 10:11 AM
Albertville Albertville is offline
初级会员
 
Join Date: 2007-12-03
Posts: 1
Albertville 现在声名狼藉
Default 为WordPress添加上一篇下一篇功能

WordPress没有内置“上一篇 下一篇”功能,可是这个功能却是我们经常用到的,它不仅可以提高网站的用户体验度,而且能留住访客的脚步,增加网站的PV值。

其实这个功能实现起来很简单,只需在文章页面(一般都是Single.php文件)添加一些代码即可。

一、添加常用的“上一篇 下一篇”代码如下:


<?php if (get_previous_post()) { previous_post_link('上一篇: %link');} else {echo "没有了,已经是最后文章";} ?>
<?php if (get_next_post()) { next_post_link('下一篇: %link');} else {echo "没有了,已经是最新文章";} ?>

二、每个网站都有不同的分类目录,如何给文章页面添加同类别文章的“上一篇 下一篇”功能呢?也很简单,代码如下:
Code:
<?php
     $categories = get_the_category();
     $categoryIDS = array();
     foreach ($categories as $category) {
         array_push($categoryIDS, $category->term_id);
     }
     $categoryIDS = implode(",", $categoryIDS);
?>
<?php if (get_previous_post($categoryIDS)) { previous_post_link('上一篇: %link','%title',true);} else { echo "没有了,已经是最后新闻";} ?>
<?php if (get_next_post($categoryIDS)) { next_post_link('下一篇: %link','%title',true);} else { echo "没有了,已经是最新新闻";} ?>
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 2 (0 members and 2 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 10:54 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.