2014-06-22 145 views
-1

我需要在帖子的分页的其他页面上显示the_content()。例如。第一页是一个名为'索引'的额外字段。第2页是'摘要',第3页显示作者信息。在第4页上,应该启动the_content。WordPress的:显示在分页的其他页面上的内容

问题是,wordpress开始计数页面,并在第4页上显示the_content就好像它会在第4页(所以4次<! - 下一页 - >)。

我这样做:

$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
if (!preg_match('#/\d+/?#', $url)) { 
    the_field("index"); 
} elseif(false !== strpos($url,'/2/')) { 
    get_the_author_meta('first_name').' '.get_the_author_meta('last_name'); 
} elseif(false !== strpos($url,'/3/')) { 
    the_field("abstract"); 
} else { 
    the_content(); 
} 

但是,正如我所说的,the_content()开始,就好像它是第4页。我知道它应该这样的行为。 我该怎么做第4页就像第1页the_content()。

更新澄清:

我想拿出the_content()在我的主题文件内容的single.php显示我在前端文章。我有分页激活功能,所以只要发现<! - 下一页 - > Wordpress分页我的文章。这是原生的WordPress的行为。

但我想提出一些额外的内容之前the_content()。

Page 1: Index 
Page 2: Abstract 
Page 3: Author 
Page 4: START the_content() page 1 
Page 5: the_content() page 2 
Page 6: the_content() page 3 

等等...

我与我上面写的代码这样做。我检查我们是哪一页。 ($ url,'/ 3 /')是第3页。

即使我检查第4页(在其他部分)并放出the_content()在这里wordpress将第4页的the_content() 4次后的部分<! - 下一页 - >。我并未从第4页的the_content()开始,但它从第1页开始,但不显示它。内部页面计数器运行一些方法。

如何启动第4页上的the_content()?或者我怎样才能防止Wordpress计数页面?

回答

0

的第一件事我注意到的是,你正在使用正则表达式匹配页面的号码!你应该只使用$page(一个WordPress特定的全局变量)。

$ page(int)由查询var页指定的帖子的页面。 http://codex.wordpress.org/Global_Variables

但是我建议使用简码,比编辑single.php更容易,让更多的灵活性。

[section page='index'] // obviously you need to build a custom shortcode 

<!--nextpage--> 

[section page='abstract'] 

<!--nextpage--> 

[section page='author'] 

<!--nextpage--> 

<!-- page's 1 content --> 

<!--nextpage--> 

<!-- page's 2 content --> 

<!--nextpage--> 

<!-- page's 3 content --> 
相关问题