0
function wp_link_pages_titled($args = '',$name,$author) {
    $defaults = array(
        'before' => '<p>' . __('Pages:'), 
        'after' => '</p>',
        '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 ) ) );
            }

        $part_content2 = $pages[$i-1];
            $has_part_title2 = strpos( $part_content2, '<!--pageauthor:' );
             if( 1 === $has_part_title ) {
                $end2 = strpos( $part_content2, '-->' );
                $title2 = trim( str_replace( '<!--pageauthor:', '', substr( $part_content2, 0, $end2 ) ) );
            }

            $output .= '<tr><td class="category2_td1">Mirror '.$i.'</td><td class="category2_td1">';
            if ( ($i != $page) || ((!$more) && ($page==1)) ) {
                $output .= _wp_link_page($i);
            }

            $title = isset( $title ) && ( strlen( $title ) > 0 ) ? $title : $name;

            $title2 = isset( $title2 ) && ( strlen( $title2 ) > 0 ) ? $title2 : $author;
            $output .= $link_before . $title . $link_after;
            if ( ($i != $page) || ((!$more) && ($page==1)) )
                $output .= '</a></td><td class="category2_td1">'.$title2.'</td></tr>';
        else
                $output .= '</td><td class="category2_td1">'.$title2.'</td></tr>';
        }
        $output .= $after;
    }
    if ( $echo )
        echo $output;
    return $output;
}

I'm trying to allow the adding of the author name to the post with the use of the wp link pages tag so it is like this

<!--nextpage--><!--pagetitle: daily --><!--pageauthor: dan -->

the original code which works for these tags

<!--nextpage--><!--pagetitle: daily -->

function wp_link_pages_titled($args = '',$name) {
    $defaults = array(
        'before' => '<p>' . __('Pages:'), 
        'after' => '</p>',
        '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 : $name;
            $output .= $link_before . $title . $link_after;
            if ( ($i != $page) || ((!$more) && ($page==1)) )
                $output .= '</a>';
        }
        $output .= $after;
    }
    if ( $echo )
        echo $output;
    return $output;
}

Anyone have any ideas how to add the extra author tag for <!--nextpage--> tag?

1

You check for <!--pageauthor:, but you expect it to start on the second character (1 === $has_part_title2) (you even have a typo there and left the 2 off). This will not work, because <!--pagetitle: is still part of that string (you don't chop it off).

You should either chop it off (do a substring in $part_content2 = $pages[$i-1]), or allow it to appear later in the post (false !== $has_part_title2).

$has_part_title2 = strpos( $part_content2, '<!--pageauthor:' );
if( false !== $has_part_title2 ) {
    $end2 = strpos( $part_content2, '-->' );
    $title2 = trim( str_replace( '<!--pageauthor:', '', substr( $part_content2, 0, $end2 ) ) );
}
3
  • okay I'm not that great at php so I'm a bit confused on how to do it – user7715 Aug 14 '11 at 20:49
  • @user7715: I updated my answer with a lines that you should change. – Jan Fabry Aug 14 '11 at 21:07
  • doesn't work<!--nextpage--><!--pagetitle: daily --><!--pageauthor: dan --> the pagetitle works but the page author does not – user7715 Aug 14 '11 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.