2

In Wordpress we can split a post with <!--nextpage-->, if we put it in the code version of the post-editor. This is working for me. BUT what is, if I want to hardcode this in the themes loop file? How can I get this to work?

Assume I have something like this in my loop file:

<?php the_excerpt(); ?>
<?php the_content(); ?>
<?php wp_link_pages(foobarbaz); ?>

Obviously the following solution won't work:

<?php the_excerpt(); ?>
<!--nextpage-->
<?php the_content(); ?>
<?php wp_link_pages(foobarbaz); ?>

I have no clue where I could find the right php function that is executed when <!--nextpage--> gets parsed in the code editor. The only solution I can think of is creating a new post with just <!--nextpage--> in it and somehow try to hardcode this specific post inside the loop file. But there has to be a much better and cleaner way of doing it...

Any suggestions?

4

1 回答 1

0

不确定您要做什么,但您可以在“设置”->“阅读”选项卡上控制存档页面上显示的帖子数量。

如果您想将内容拆分为单个帖子,我认为最好的方法是连接到“the_content”过滤器。我不确定您是否有要拆分帖子的标准,但如果它是字数并且您不想使用the_excerpt;,您可以编写一个函数(在主题的 functions.php 文件中),如下所示:

add_filter('the_content', 'your_post_split');
function your_post_split($content) {
//do something with the content and insert <!--nextpage--> 
return $content;
}

编写过滤器时,请确保始终返回进入函数的变量。

如果您想在帖子前加上摘录文本,请尝试以下操作:

function your_post_split($content) {
 global $post;
 $content = $post->post_excerpt . $content;
 return $content;
}

从您的模板中取出<?php the_excerpt; ?>

于 2013-07-06T22:02:16.447 回答