Veja uma maneira de oferecer suporte a títulos de paginação no formulário:
<!--nextpage(.*?)?-->
de uma maneira semelhante, como o núcleo suporta <!--more(.*?)?-->
.
Veja um exemplo:
<!--nextpage Planets -->
Let's talk about the Planets
<!--nextpage Mercury -->
Exotic Mercury
<!--nextpage Venus-->
Beautiful Venus
<!--nextpage Earth -->
Our Blue Earth
<!--nextpage Mars -->
The Red Planet
com a saída semelhante a:
IssofoitestadonotemaTwentySixteen,ondeeutivequeajustaropaddingewidthumpouco:
.page-linksa,.page-links>span{width:auto;padding:05px;}
Plugindedemonstração
Esteéumplugindedemonstraçãoqueusaosfiltroscontent_pagination
,wp_link_pages_link
,pre_handle_404
ewp_link_pages_args
parasuportarestaextensãodomarcadornextpage(PHP5.4+):
<?php/***PluginName:ContentPaginationTitles*Description:Supportfor<!--nextpage(.*?)?-->inthepostcontent*Version:1.0.1*PluginURI:http://wordpress.stackexchange.com/a/227022/26350*/namespaceWPSE\Question202709;add_action('init',function(){$main=newMain;$main->init();});classMain{private$pagination_titles;publicfunctioninit(){add_filter('pre_handle_404',[$this,'pre_handle_404'],10,2);add_filter('content_pagination',[$this,'content_pagination'],-1,2);add_filter('wp_link_pages_link',[$this,'wp_link_pages_link'],10,2);add_filter('wp_link_pages_args',[$this,'wp_link_pages_args'],PHP_INT_MAX);}publicfunctioncontent_pagination($pages,$post){//Emptycontentpaginationtitlesforeachrun$this->pagination_titles=[];//Nothingtodoifthepostcontentdoesn'tcontainpaginationtitlesif(false===stripos($post->post_content,'<!--nextpage'))return$pages;//Collectpaginationtitlespreg_match_all('/<!--nextpage(.*?)?-->/i',$post->post_content,$matches);if(isset($matches[1]))$this->pagination_titles=$matches[1];//Override$pagesaccordingtoournewextendednextpagesupport$pages=preg_split('/<!--nextpage(.*?)?-->/i',$post->post_content);//nextpagemarkeratthetopif(isset($pages[0])&&''==trim($pages[0])){//removetheemptypagearray_shift($pages);}//nextpagemarkernotatthetopelse{//addthefirstnumericpaginationtitlearray_unshift($this->pagination_titles,'1');}return$pages;}publicfunctionwp_link_pages_link($link,$i){if(!empty($this->pagination_titles)){$from='{{TITLE}}';$to=!empty($this->pagination_titles[$i-1])?$this->pagination_titles[$i-1]:$i;$link=str_replace($from,$to,$link);}return$link;}publicfunctionwp_link_pages_args($params){if(!empty($this->pagination_titles)){$params['next_or_number']='number';$params['pagelink']=str_replace('%','{{TITLE}}',$params['pagelink']);}return$params;}/***BasedonthenextpagecheckinWP::handle_404()*/publicfunctionpre_handle_404($bool,\WP_Query$q){global$wp;if($q->posts&&is_singular()){if($q->postinstanceof\WP_Post)$p=clone$q->post;//checkforpagedcontentthatexceedsthemaxnumberofpages$next='<!--nextpage';if($p&&false!==stripos($p->post_content,$next)&&!empty($wp->query_vars['page'])){$page=trim($wp->query_vars['page'],'/');$success=(int)$page<=(substr_count($p->post_content,$next)+1);if($success){status_header(200);$bool=true;}}}return$bool;}}//endclass
Instalação:Crieoarquivo/wp-content/plugins/content-pagination-titles/content-pagination-titles.php
eativeoplugin.Sempreéumaboaideiafazerbackupantesdetestarqualquerplug-in.
Seomarcadortoppróximapáginaestiverfaltando,oprimeirotítulodepaginaçãoseránumérico.
Alémdisso,seumtítulodepaginaçãodeconteúdoestiverfaltando,porexemplo,<!--nextpage-->
,eleseránumérico,exatamentecomoesperado.
Esqueci-meprimeirodoerronextpagenaclasseWP
,queaparecesemodificarmosonúmerodepáginasatravésdofiltrocontent_pagination
.Istofoirecentementereportadopor@PieterGoosenaquiem
Tentamos superar isso em nosso plug-in de demonstração com um retorno de chamada do filtro pre_handle_404
, com base na verificação da classe WP
aqui , onde verificamos <!--nextpage
em vez de <!--nextpage-->
.
Testes
Aqui estão alguns testes adicionais:
Teste nº 1
<!--nextpage-->
Let's talk about the Planets
<!--nextpage-->
Exotic Mercury
<!--nextpage-->
Beautiful Venus
<!--nextpage-->
Our Blue Earth
<!--nextpage-->
The Red Planet
Saída para 1 selecionada:
comoesperado.
Testenº2
Let'stalkaboutthePlanets<!--nextpage-->ExoticMercury<!--nextpage-->BeautifulVenus<!--nextpage-->OurBlueEarth<!--nextpage-->TheRedPlanet
Saídapara5selecionada:
comoesperado.
Testenº3
<!--nextpage-->Let'stalkaboutthePlanets<!--nextpageMercury-->ExoticMercury<!--nextpage-->BeautifulVenus<!--nextpageEarth-->OurBlueEarth<!--nextpageMars-->TheRedPlanet
Saídapara3selecionada:
comoesperado.
Teste#4
Let'stalkaboutthePlanets<!--nextpageMercury-->ExoticMercury<!--nextpageVenus-->BeautifulVenus<!--nextpageEarth-->OurBlueEarth<!--nextpageMars-->TheRedPlanet
SaídacomTerraselecionada:
como esperado.
Alternativas
Outra forma seria modificá-lo para suportar títulos de paginação a serem adicionados com:
<!--pt Earth-->
Também pode ser útil apoiar um único comentário para todos os títulos de paginação ( pts ):
<!--pts Planets|Mercury|Venus|Earth|Mars -->
ou talvez por meio de campos personalizados?