首页 文章

Wordpress:在分页的另一页上显示内容

提问于
浏览
-1

我需要在帖子的分页的另一页上显示the_content() . 例如 . 第一页是一个名为'index'的额外字段 . 第2页是“摘要”,第3页显示了作者信息 . 在第4页,the_content应该开始 .

问题是wordpress开始计算页面,并且在第4页上,the_content显示为就像它在第4页上一样(因此在<! - next page - > 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页就像the_content()的第1页 .

UPDATE FOR CLARIFY:

我想在我的主题文件content-single.php中放出the_content()来在前端显示我的文章 . 我有分页活动,所以只要找到<! - 下一页 - >,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页(在else部分中)并且输出了the_content(),这里wordpress会输出the_content()的第4页,所以4次后的部分<! - next page - > . 我没有使用第4页的the_content()开始,但它从第1页开始,但不显示它 . 内部页面计数器运行一些方式 .

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

1 回答

  • 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 -->
    

相关问题