Пример #1
0
 function widget($args, $instance)
 {
     // If Co-Authors plus plugin exists display all co-aothor profiles one after another
     if (function_exists('coauthors_posts_links')) {
         $i = new CoAuthorsIterator();
         $cnt = 1;
         while ($i->iterate()) {
             // the iterator overwrites the global authordata variable on each iteration
             $instance['seq'] = $cnt++;
             $instance['isLast'] = $i->is_last();
             $this->_displayAuthor($args, $instance);
         }
     } else {
         // Normal behavior, one author per blog post
         $instance['seq'] = 1;
         $instance['isLast'] = true;
         $this->_displayAuthor($args, $instance);
     }
 }
Пример #2
0
function coauthors__echo($tag, $type = 'tag', $separators = array(), $tag_args = null, $echo = true)
{
    // Define the standard output separator. Constant support is for backwards compat.
    // @see https://github.com/danielbachhuber/Co-Authors-Plus/issues/12
    $default_before = defined('COAUTHORS_DEFAULT_BEFORE') ? COAUTHORS_DEFAULT_BEFORE : '';
    $default_between = defined('COAUTHORS_DEFAULT_BETWEEN') ? COAUTHORS_DEFAULT_BETWEEN : ', ';
    $default_between_last = defined('COAUTHORS_DEFAULT_BETWEEN_LAST') ? COAUTHORS_DEFAULT_BETWEEN_LAST : __(' and ', 'co-authors-plus');
    $default_after = defined('COAUTHORS_DEFAULT_AFTER') ? COAUTHORS_DEFAULT_AFTER : '';
    if (!isset($separators['before']) || $separators['before'] === NULL) {
        $separators['before'] = apply_filters('coauthors_default_before', $default_before);
    }
    if (!isset($separators['between']) || $separators['between'] === NULL) {
        $separators['between'] = apply_filters('coauthors_default_between', $default_between);
    }
    if (!isset($separators['betweenLast']) || $separators['betweenLast'] === NULL) {
        $separators['betweenLast'] = apply_filters('coauthors_default_between_last', $default_between_last);
    }
    if (!isset($separators['after']) || $separators['after'] === NULL) {
        $separators['after'] = apply_filters('coauthors_default_after', $default_after);
    }
    $output = '';
    $i = new CoAuthorsIterator();
    $output .= $separators['before'];
    $i->iterate();
    do {
        $author_text = '';
        if ($type == 'tag') {
            $author_text = $tag($tag_args);
        } elseif ($type == 'field' && isset($i->current_author->{$tag})) {
            $author_text = $i->current_author->{$tag};
        } elseif ($type == 'callback' && is_callable($tag)) {
            $author_text = call_user_func($tag, $i->current_author);
        }
        // Fallback to user_login if we get something empty
        if (empty($author_text)) {
            $author_text = $i->current_author->user_login;
        }
        // Append separators
        if (!$i->is_first() && $i->count() > 2) {
            $output .= $separators['between'];
        }
        if ($i->is_last() && $i->count() > 1) {
            $output = rtrim($output, $separators['between']);
            $output .= $separators['betweenLast'];
        }
        $output .= $author_text;
    } while ($i->iterate());
    $output .= $separators['after'];
    if ($echo) {
        echo $output;
    }
    return $output;
}
Пример #3
0
 /**
  * 21. This function/shortcode will show all authors on a post
  *
  * @example <code>[show_authors]</code> is the default usage
  * @example <code>[show_authors]</code>
  */
 function show_multiple_authors()
 {
     if (class_exists('CoAuthorsIterator')) {
         $i = new CoAuthorsIterator();
         $return = '';
         $i->iterate();
         $return .= '<a href="' . get_author_posts_url(get_the_author_meta('ID')) . '">' . get_the_author_meta('display_name') . '</a>';
         while ($i->iterate()) {
             $return .= $i->is_last() ? ' and ' : ', ';
             $return .= '<a href="' . get_author_posts_url(get_the_author_meta('ID')) . '">' . get_the_author_meta('display_name') . '</a>';
         }
         return $return;
     } else {
         //fallback
     }
 }
Пример #4
0
function coauthors__echo($tag, $between, $betweenLast, $before, $after)
{
    $i = new CoAuthorsIterator();
    echo $before;
    if ($i->iterate()) {
        $tag();
    }
    while ($i->iterate()) {
        echo $i->is_last() ? $betweenLast : $between;
        $tag();
    }
    echo $after;
}