我正在努力使我的主题与Co-Authors Plus plugin 如果有帖子的话,给合著者看看。我花了大约30分钟的时间试图说服自己,我理解以下显示文章作者和日期的代码:
function posted_on() {
global $post;
$author_id=$post->post_author;
$time_string = \'<time class="entry-date published updated" datetime="%1$s">%2$s</time>\';
if ( get_the_time( \'U\' ) !== get_the_modified_time( \'U\' ) ) {
$time_string = \'<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>\';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( \'c\' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( \'c\' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
__( \'<i class="entry-date">\'. get_the_date( \'F d, Y\' ) .\'</i>\' ),
\'<a href="\' . esc_url( get_permalink() ) . \'" rel="bookmark">\' . $time_string . \'</a>\'
);
$byline = sprintf (
__( \'by %s\' ),
\'<span class="author vcard"><a class="url fn n" href="\' . esc_url(
get_author_posts_url( $author_id )
) . \'">\' . esc_html( get_the_author_meta( \'display_name\', $author_id ) ) . \'</a>\' . \'</span>\'
);
echo \'<span class="posted-on">\' . $posted_on . \'</span><i><span class="byline"> \' . $byline . \'</span></i>\'; // WPCS: XSS OK.
}
所以我添加了一个函数:
$byline = sprintf(
__(\'by %s\'),
/*Added this*/
if (function_exists(\'coauthors_posts_links\')) {
\'<span class="author vcard">\'.esc_html(coauthors_posts_links()).
\'</span>\'
} else {
\'<span class="author vcard"><a class="url fn n" href="\'.esc_url(
get_author_posts_url($author_id)
).
\'">\'.esc_html(get_the_author_meta(\'display_name\', $author_id)).
\'</a>\'.
\'</span>\'
}
);
这个函数应该像。。。如果此帖子包含合著者,
显示作者和合著者。
如果帖子不包含合著者,
显示默认的作者链接。
但这只是个错误。可能需要一些建议。