hier noch der code;
PHP
<?php
/*
Plugin Name: Authors Widget
Plugin URI: http://blog.fleischer.hu/wordpress/authors/
Description: Authors Widget shows the list or cloud of the authors, with the number of posts, link to RSS feed next to their name, avatar. It is useful in a multi-author blog, where you want to have the list in the sidemenu.
Version: 1.7
Author: Gavriel Fleischer
Author URI: http://blog.fleischer.hu/gavriel/
*/
// Multi-language support
if (defined('WPLANG') && function_exists('load_plugin_textdomain')) {
load_plugin_textdomain('authors', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/lang');
}
// Widget stuff
function widget_authors_register() {
if ( function_exists('register_sidebar_widget') ) :
if ( function_exists('seo_tag_cloud_generate') ) :
function widget_authors_cloud($args = '') {
global $wpdb;
$defaults = array(
'optioncount' => false, 'exclude_admin' => true,
'show_fullname' => false, 'hide_empty' => true,
'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
'limit' => 0, 'em_step' => 0.1
);
$r = wp_parse_args( $args, $defaults );
extract($r, EXTR_SKIP);
$return = '';
$authors = $wpdb->get_results('SELECT ID, user_nicename, display_name FROM '.$wpdb->users.' ' . ($exclude_admin ? 'WHERE ID <> 1 ' : '') . 'ORDER BY display_name');
$author_count = array();
foreach ((array) $wpdb->get_results('SELECT DISTINCT post_author, COUNT(ID) AS count FROM '.$wpdb->posts.' WHERE post_type = "post" AND ' . get_private_posts_cap_sql( 'post' ) . ' GROUP BY post_author') as $row) {
$author_count[$row->post_author] = $row->count;
}
foreach ( (array) $authors as $key => $author ) {
$posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
if ( $posts != 0 || !$hide_empty ) {
$author = get_userdata( $author->ID );
$name = $author->display_name;
if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )
$name = "$author->first_name $author->last_name";
if ( $posts == 0 ) {
if ( !$hide_empty )
$link = '';
}
else {
$link = get_author_posts_url($author->ID, $author->user_nicename);
}
$authors[$key]->name = $name;
$authors[$key]->count = $posts;
$authors[$key]->link = $link;
$authors[$key]->extra = $optioncount ? '('.$posts.')' : '';
}
else
unset($authors[$key]);
}
$args['number'] = $limit;
$return = seo_tag_cloud_generate( $authors, $args ); // Here's where those top tags get sorted according to $args
echo $return;
}
endif;
function widget_authors_dropdown($args = '') {
# $echo = $args['echo'];
$args['echo'] = false;
unset($args['feed']);
$arr = array_slice(explode('<li>', wp_list_authors($args)), 1);
switch ($order) {
case 'posts': usort($arr, 'widget_authors_sort_by_posts');break;
case 'name':
default:
}
$options = '';
foreach ($arr as $author) {
preg_match('#<a href="([^"]*)"[^>]*>([^<]*)</a>( \(([0-9]*)\))?#', $author, $matches);
# $authors[] = array('url'=>$matches[1], 'name'=>$matches[2], 'count'=>$matches[4]);
$options .= '<option value="'.htmlspecialchars($matches[1]).'">'.$matches[2].($args['optioncount'] ? ' ('.$matches[4].')' : '').'</option>'."\n";
}
unset($arr);
$dropdown = '<select onchange="window.location=this.options[this.selectedIndex].value">'."\n";
$dropdown .= '<option value="#">'.__('Select Author...', 'authors').'</option>'."\n";
$dropdown .= $options;
$dropdown .= '</select>';
# if ($echo)
echo $dropdown;
# return $dropdown;
}
Alles anzeigen