Dragon
甬力三甚甬力三甚  2015-08-05 15:35 越鹰家博客 隐藏边栏 |   抢沙发  1 
文章评分 0 次,平均分 0.0

不少WordPress朋友总喜欢给长一点的文章进行分页,但是默认情况下,在WordPress编辑器中,是没有显示“下一页”按钮的,每次都要手动添加分页代码 <!--nextpage-->是一件非常费力的事,其实,我们只要在当前主题的 functions.php 添加下面的代码,就可以显示“下一页”按钮啦。

  1. <span class="co4">/**</span>
  2. <span class="co4">?* 在 WordPress 编辑器添加“下一页”按钮</span>
  3. <span class="co4">?* http://www.wpdaxue.com/add-next-page-button-wordpress-post-editor.html</span>
  4. <span class="co4">?*/</span>
  5. add_filter<span class="br0">(</span><span class="st_h">'mce_buttons'</span><span class="sy0">,</span><span class="st_h">'wpdaxue_add_next_page_button'</span><span class="br0">)</span><span class="sy0">;</span>
  6. <span class="kw2">function</span> wpdaxue_add_next_page_button<span class="br0">(</span><span class="re0">$mce_buttons</span><span class="br0">)</span> <span class="br0">{</span>
  7. 	<span class="re0">$pos</span> <span class="sy0">=</span> <span class="kw3">array_search</span><span class="br0">(</span><span class="st_h">'wp_more'</span><span class="sy0">,</span><span class="re0">$mce_buttons</span><span class="sy0">,</span><span class="kw4">true</span><span class="br0">)</span><span class="sy0">;</span>
  8. 	<span class="kw1">if</span> <span class="br0">(</span><span class="re0">$pos</span> <span class="sy0">!==</span> <span class="kw4">false</span><span class="br0">)</span> <span class="br0">{</span>
  9. 		<span class="re0">$tmp_buttons</span> <span class="sy0">=</span> <span class="kw3">array_slice</span><span class="br0">(</span><span class="re0">$mce_buttons</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="re0">$pos</span><span class="sy0">+</span><span class="nu0">1</span><span class="br0">)</span><span class="sy0">;</span>
  10. 		<span class="re0">$tmp_buttons</span><span class="br0">[</span><span class="br0">]</span> <span class="sy0">=</span> <span class="st_h">'wp_page'</span><span class="sy0">;</span>
  11. 		<span class="re0">$mce_buttons</span> <span class="sy0">=</span> <span class="kw3">array_merge</span><span class="br0">(</span><span class="re0">$tmp_buttons</span><span class="sy0">,</span> <span class="kw3">array_slice</span><span class="br0">(</span><span class="re0">$mce_buttons</span><span class="sy0">,</span> <span class="re0">$pos</span><span class="sy0">+</span><span class="nu0">1</span><span class="br0">)</span><span class="br0">)</span><span class="sy0">;</span>
  12. 	<span class="br0">}</span>
  13. 	<span class="kw1">return</span> <span class="re0">$mce_buttons</span><span class="sy0">;</span>
  14. <span class="br0">}</span>

最终效果如下图所示:

add-next-page-button-reinjia_com

文章页面演示地址请浏览 http://www.9frc.com

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

甬力三甚
甬力三甚 关注:0    粉丝:0 最后编辑于:2020-03-07
IT民工,专注于网络营销、策划、经济分析。越鹰网络创立者。

发表评论

表情 格式 链接 私密 签到

扫一扫二维码分享