0

<!--nextpage-->投稿コンテンツタグに追加する関数を書きたいので、この関数を書きます:

<?php
function output($content) {
$output = $content.'<!--nextpage-->'.$content;

return $output;
}

add_filter('the_content','output');

?>

機能はタグを追加<!--nextpage-->しますが、投稿を表示するとこのタグは機能しません。これは HTML コメントのようなものです。この問題を解決するための解決策はありますか?

多分私は使用しなければなりませんthe_contentwp_insert_post_data

4

1 に答える 1

1

The conversion from text with <!--nextpage--> into "pages" happens in setup_postdata. But the hook you use executes when the template tag with the same name, the_content is called. So what this means is you have to change the content before the loop starts. It can be a bit tricky. Off the top of my head I don't know of any suitable hooks but you can check the source code for setup_postdata and there might be one. In the theme, though, you can access $posts so if you put this in a template, it should work:

global $posts;
array_map( function( $apost ) {
    $apost->post_content = $apost->post_content.'<!--nextpage-->'.$apost->post_content;
    return $apost;
}, $posts );

If you don't have PHP version => 5.3 you can't use anonymous functions. In that case, this version will work:

global $posts;
function output( $apost ) {
    $apost->post_content = $apost->post_content.'<!--nextpage-->'.$apost->post_content;
    return $apost;
}
array_map( 'output', $posts );
于 2013-02-05T17:32:56.500 に答える