WordPress 4.4中的新内容分页过滤器自WordPress 4.4起,我们可以使用content_pagination
过滤器(参见票据#9911 )
/**
* Filter the "pages" derived from splitting the post content.
*
* "Pages" are determined by splitting the post content based on the presence
* of `<!-- nextpage -->` tags.
*
* @since 4.4.0
*
* @param array $pages Array of "pages" derived from the post content.
* of `<!-- nextpage -->` tags..
* @param WP_Post $post Current post object.
*/
$pages = apply_filters( \'content_pagination\', $pages, $post );
此筛选器位于
setup_postdata()
的方法
WP_Query
类并将使修改分页页更容易。
下面是几个如何删除内容分页的示例(PHP 5.4+):
示例#1
以下是禁用内容分页的方法:
/**
* Disable content pagination
*
* @link http://wordpress.stackexchange.com/a/208784/26350
*/
add_filter( \'content_pagination\', function( $pages )
{
$pages = [ join( \'\', $pages ) ];
return $pages;
} );
示例2如果我们只想以主查询循环为目标:
/**
* Disable content pagination in the main loop
*
* @link http://wordpress.stackexchange.com/a/208784/26350
*/
add_filter( \'content_pagination\', function( $pages )
{
if ( in_the_loop() )
$pages = [ join( \'\', $pages ) ];
return $pages;
} );
如果我们只想针对
post
主回路中的post类型:
/**
* Disable content pagination for post post type in the main loop
*
* @link http://wordpress.stackexchange.com/a/208784/26350
*/
add_filter( \'content_pagination\', function( $pages, $post )
{
if ( in_the_loop() && \'post\' === $post->post_type )
$pages = [ join( \'\', $pages ) ];
return $pages;
}, 10, 2 );