如何更改分页符编号?

时间:2016-08-20 作者:Avinash Patel

我正在使用<!--nextpage--> 在多个页面上打断我的帖子。这很好用。但我想进一步更改页码。

如果您访问this post 您将注意到分页符。我想把第一页改为“问题”,而第二页改为“答案”

我在this page 在我的主题中尝试了以下代码functions.php 但它破坏了我的网站。

<?php wp_link_pages(\'before=To read this story, &after=. &next_or_number=next
&previouspagelink=you can go back to the previous page
&nextpagelink= or you can read on to the next page\'); ?>
你能帮我找到正确的代码吗。如果这有帮助的话,我不想保留超过两页的内容。如果有人能帮我找到它的快捷码,那就是冰淇淋上面的樱桃:)

2 个回复
SO网友:CodeMascot

把这个功能放在你身上functions.php -

function the_dramatist_wp_link_pages( $args = \'\' ) {
    global $page, $numpages, $multipage, $more;

    $defaults = array(
        \'before\'           => \'<p>\' . __( \'Pages:\' ),
        \'after\'            => \'</p>\',
        \'link_before\'      => \'\',
        \'link_after\'       => \'\',
        \'next_or_number\'   => \'number\',
        \'separator\'        => \' \',
        \'nextpagelink\'     => __( \'Next page\' ),
        \'previouspagelink\' => __( \'Previous page\' ),
        \'pagelink\'         => \'%\',
        \'echo\'             => 1
    );

    $params = wp_parse_args( $args, $defaults );

    /**
     * Filters the arguments used in retrieving page links for paginated posts.
     *
     * @since 3.0.0
     *
     * @param array $params An array of arguments for page links for paginated posts.
     */
    $r = apply_filters( \'wp_link_pages_args\', $params );

    $output = \'\';
    if ( $multipage ) {
        if ( \'number\' == $r[\'next_or_number\'] ) {
            $output .= $r[\'before\'];
            for ( $i = 1; $i <= $numpages; $i++ ) {
                if ( $i % 2 == 0) {
                    $link = $r[\'link_before\'] . str_replace( \'%\', \'Answer\', $r[\'pagelink\'] ) . $r[\'link_after\'];
                } else {
                    $link = $r[\'link_before\'] . str_replace( \'%\', \'Question\', $r[\'pagelink\'] ) . $r[\'link_after\'];
                }
                if ( $i != $page || ! $more && 1 == $page ) {
                    $link = _wp_link_page( $i ) . $link . \'</a>\';
                }
                /**
                 * Filters the HTML output of individual page number links.
                 *
                 * @since 3.6.0
                 *
                 * @param string $link The page number HTML output.
                 * @param int    $i    Page number for paginated posts\' page links.
                 */
                $link = apply_filters( \'wp_link_pages_link\', $link, $i );

                // Use the custom links separator beginning with the second link.
                $output .= ( 1 === $i ) ? \' \' : $r[\'separator\'];
                $output .= $link;
            }
            $output .= $r[\'after\'];
        } elseif ( $more ) {
            $output .= $r[\'before\'];
            $prev = $page - 1;
            if ( $prev > 0 ) {
                $link = _wp_link_page( $prev ) . $r[\'link_before\'] . $r[\'previouspagelink\'] . $r[\'link_after\'] . \'</a>\';

                /** This filter is documented in wp-includes/post-template.php */
                $output .= apply_filters( \'wp_link_pages_link\', $link, $prev );
            }
            $next = $page + 1;
            if ( $next <= $numpages ) {
                if ( $prev ) {
                    $output .= $r[\'separator\'];
                }
                $link = _wp_link_page( $next ) . $r[\'link_before\'] . $r[\'nextpagelink\'] . $r[\'link_after\'] . \'</a>\';

                /** This filter is documented in wp-includes/post-template.php */
                $output .= apply_filters( \'wp_link_pages_link\', $link, $next );
            }
            $output .= $r[\'after\'];
        }
    }

    /**
     * Filters the HTML output of page links for paginated posts.
     *
     * @since 3.6.0
     *
     * @param string $output HTML output of paginated posts\' page links.
     * @param array  $args   An array of arguments.
     */
    $html = apply_filters( \'wp_link_pages\', $output, $args );

    if ( $r[\'echo\'] ) {
        echo $html;
    }
    return $html;
}
然后转到主题目录。搜索并替换wp_link_pages 函数名称the_dramatist_wp_link_pages. 它会按照你的意愿工作。通常是wp_link_pages 存在于content-{template-name}.php. 所以,如果您的主题中有任何这些文件,请先查看主题。这里我添加了一个屏幕截图-enter image description here

然后再做造型。玩得高兴

The function works on odd-even basis. It considers the odd part as \'Question\' and the even part as \'Answer\'

SO网友:cjbj

法典中的例子有错误的引号。开发人员区域有关于如何使用的更多详细信息wp_link_pages. 示例用法:

<?php
$args = array(
    \'before\'           => \'<p>\' . __( \'To read this story\' ),
    \'after\'            => \'</p>\',
    \'link_before\'      => \'\',
    \'link_after\'       => \'\',
    \'next_or_number\'   => \'next\',
    \'separator\'        => \' \',
    \'nextpagelink\'     => __( \'you can go back to the previous page\' ),
    \'previouspagelink\' => __( \' or you can read on to the next page\' ),
    \'pagelink\'         => \'%\',
    \'echo\'             => 1
    );
wp_link_pages ($args);
?>

相关推荐

GoBlog Free Pagination Issue

第一次海报,我的名字是约翰尼。:)我已经为我的网站建立了一个存档页面,我非常自豪(使用Elementor),但我不希望这个主题的主页分页。我想在主页上显示6篇最新的帖子,如果读者想找到更多,他们必须点击顶部的存档页面。充分披露:我是一个完全的n00b在任何类型的编程。我以前做过一些非常基本的python,但仅此而已。我找到了用于分页的代码,它如下所示:?> <div class="grids grids1"> <div class=&qu