WordPress.org

Ready to get started?Download WordPress

Forums

How to have multipage links as titles instead of numbers ? (2 posts)

  1. sugardaddy
    Member
    Posted 2 years ago #

    Hi !
    I'm using successfully the <!--nextpage--> tag into my posts (custom posts actually).
    What I'm getting is a links list of pages by number.
    My question is : is there any way to have custom titles for these links instead of numbers ?

    All what I found is related to SEO...

    Thanks a lot for your help !

  2. sugardaddy
    Member
    Posted 2 years ago #

    Reply at myself...
    I found this solution, which is good for now but I'm dreaming about a plugin which has an integration in the editor to insert titles as you insert the next-page tag.

    function wp_link_pages_titled($args = '') {
        $defaults = array(
            'before' => '<div id="submenu">',
            'after' => '</div>',
            'link_before' => '',
            'link_after' => '',
            'echo' => 1
        );
    
        $r = wp_parse_args( $args, $defaults );
        extract( $r, EXTR_SKIP );
    
        global $page, $numpages, $multipage, $more, $pagenow, $pages;
    
        $output = '';
        if ( $multipage ) {
            $output .= $before;
            for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
                $part_content = $pages[$i-1];
                $has_part_title = strpos( $part_content, '<!--pagetitle:' );
                if( 0 === $has_part_title ) {
                    $end = strpos( $part_content, '-->' );
                    $title = trim( str_replace( '<!--pagetitle:', '', substr( $part_content, 0, $end ) ) );
                }
                $output .= '';
                if ( ($i != $page) || ((!$more) && ($page==1)) ) {
                    $output .= _wp_link_page($i);
                }
                $title = isset( $title ) && ( strlen( $title ) > 0 ) ? $title : '';
                $output .= $link_before . $title . $link_after;
                if ( ($i != $page) || ((!$more) && ($page==1)) )
                    $output .= '</a>';
            }
            $output .= $after;
        }
        if ( $echo )
            echo $output;
        return $output;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic