大多数的WordPress主题都有文章分页功能,或者会有“阅读全文”的功能,今日WordPress主题站就为大家分享为WordPress文章添加分页和阅读全文方法。

添加函数

复制下方代码到主题的 functions.php 文件里面:

function io_link_pages() {

global $wp_query, $numpages;

if(isset( $wp_query->query_vars[ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’view\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ] ) && $wp_query->query_vars[ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’view\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ] === \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’all\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’){

echo \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'<div class=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”page-nav text-center my-3\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”><a href=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ . get_permalink() . \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”><span class=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”all\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>分页阅读</span></a></div>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’;

} elseif ( 1 < $numpages ) {

wp_link_pages(array(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’before\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'<div class=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”page-nav text-center my-3\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’after\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’next_or_number\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’next\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’previouspagelink\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'<span><i class=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”iconfont icon-arrow-l\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”></i></span>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’nextpagelink\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”));

wp_link_pages(array(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’before\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’after\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’next_or_number\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’number\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’link_before\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ =>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'<span>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’link_after\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’=>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'</span>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’));

wp_link_pages(array(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’before\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’after\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’next_or_number\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’next\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’previouspagelink\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’nextpagelink\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ <span><i class=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”iconfont icon-arrow-r\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”></i></span>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’));

echo \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ <a href=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ . get_pagenum_link( 1 ) . ( preg_match( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\?/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, get_pagenum_link( 1 ) ) ? \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’&\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ : \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’?\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ) . \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’view=all\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ . \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”><span class=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”all\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>阅读全文</span></a></div>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’;

}

}

add_filter( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’query_vars\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_link_pages_all_parameter_queryvars\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );

add_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’the_post\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_link_pages_all_the_post\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ , 0 );

function wp_link_pages_all_parameter_queryvars( $queryvars ) {

$queryvars[] = \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’view\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’;

return( $queryvars );

}

function wp_link_pages_all_the_post( $post ) {

global $pages, $multipage, $wp_query;

if ( isset( $wp_query->query_vars[ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’view\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ] ) && ( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’all\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ === $wp_query->query_vars[ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’view\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ] ) ) {

$multipage = true;

$post->post_content = str_replace( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'<!–nextpage–>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, $post->post_content );

$pages = array( $post->post_content );

}

}

到文章模板 single.php 文件的 the_content()下方添加下面的代码调用就可以了。

<?php io_link_pages() ?>

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部