Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function jnews_get_author_coauthor( $post_id = null, $image = true, $by_class = null, $limit = 0 ) {
- $limit = 10; /* showing author name limit */
- if ( jnews_check_coauthor_plus() ) {
- /** Get coauhtor list */
- $coauthors = get_coauthors( $post_id );
- /** Real Iterate */
- $real_i = new CoAuthorsIterator( $post_id );
- /** Custom Iterate */
- $fake_i = new CoAuthorsIterator( $post_id );
- /** Start iterate */
- $real_i->iterate();
- $fake_i->iterate();
- /** Check limiter iterate */
- $count = $fake_i->count();
- $check_limit = ( $limit > 0 && $count > $limit ) ? true : false;
- $residual = ( $check_limit ) ? $count - $limit : 0;
- $residual = ( $check_limit ) ? '<span class="meta_text separators">' . $residual . ' ' . jnews_return_translation( 'others', 'jnews', 'others' ) . '</span>' : '';
- $fake_i->count = ( $check_limit ) ? $limit + 1 : $count;
- $is_multiple = $fake_i->count() > 1 ? true : false;
- $multiple_class = $is_multiple ? 'jnews_multiple_author' : '';
- $authors = '';
- $author_image = '';
- /** Loop coauthor */
- foreach ( $coauthors as $coauthor ) {
- /** Trigger real iterate */
- $real_i->iterate();
- $output = '';
- $author_text = '';
- $guest_author = ( 'guest-author' === $coauthor->type ) ? true : false;
- /** Check author avatar */
- if ( $image && $real_i->position < 3 ) {
- if ( $guest_author ) {
- $author_image .= coauthors_get_avatar( $coauthor, 80, null, $coauthor->display_name, $multiple_class );
- } else {
- $author_image .= get_avatar( get_the_author_meta( 'ID', $coauthor->ID ), 80, null, get_the_author_meta( 'display_name', $coauthor->ID ), array( 'class' => $multiple_class ) );
- }
- if ( ! $is_multiple ) {
- $author_text .= $author_image;
- $author_image = '';
- }
- }
- /** Continue if limit reacehed */
- if ( $check_limit && $fake_i->is_last() ) {
- continue;
- }
- if ( 0 === $fake_i->position ) {
- $author_text .= '<span class="meta_text ' . $by_class . '">' . jnews_return_translation( 'by', 'jnews', 'by' ) . '</span>';
- }
- $author_text .= $guest_author ? coauthors_posts_links_single( $coauthor ) : jnews_the_author_link( $coauthor->ID, false );
- // Append separators.
- if ( 1 === $fake_i->count() - $fake_i->position ) { // last author or only author.
- $output .= $author_text;
- } elseif ( 2 === $fake_i->count() - $fake_i->position ) { // second to last.
- $output .= $author_text . '<span class="meta_text separators-and">' . jnews_return_translation( 'and', 'jnews', 'and' ) . '</span>';
- } else {
- $output .= $author_text . '<span class="meta_text separators">' . jnews_return_translation( ',', 'jnews', ',' ) . '</span>';
- }
- /** Trigger custom iterate */
- $fake_i->iterate();
- $authors .= $output;
- }
- $authors = $is_multiple ? $author_image . $authors : $authors;
- $authors .= $residual;
- return $authors;
- }
- return '';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement