The Quick & Dirty:

  • 9+ years in the biz, 10 messing around
  • All the latest in HTML, CSS, JS & PHP (Sorry, no .net or Ruby skills yet)
  • Cross-browser compatible code from Photoshop or Illustrator files.. or napkins!
  • Custom Specialities in Wordpress theming & plugins, Twitter & jQuery
  • Subversion, server-log analysis, and blocking hack-attempts (of late).
  • Data/Project Geek. I ♥ timelines.

I’ve compiled some handy PHP functions I’ve had to whip up. More extensive code-samples are also available.

Wordpress-from-Photoshop/Illustrator

Wordpress-from-static HTML

Wordpress-from-Photoshop

WordPress: Author List by Category

I just keep functioning out WP! (What can I say, it’s my job!)

This is a rework of WP’s own list_authors() function, but with some extra SQL:

[sourcecode lang="php"]

function my_list_authors_by_category($args = '', $cat_id=0) {
global $wpdb;

$defaults = array(
'optioncount' => false, ‘exclude_admin’ => true,
‘show_fullname’ => false, ‘hide_empty’ => true,
‘feed’ => ”, ‘feed_image’ => ”, ‘feed_type’ => ”, ‘echo’ => true
);

$r = wp_parse_args( $args, $defaults );
extract($r, EXTR_SKIP);

$return = ”;

/** @todo Move select to get_authors(). */
//    $authors = $wpdb->get_results(“SELECT ID, user_nicename from $wpdb->users ” . ($exclude_admin ? “WHERE user_login <> ‘admin’ ” : ”) . “ORDER BY display_name”);
//replace with the ‘author by category’ SQL
$authors = $wpdb->get_results(“SELECT distinct post_author as `ID`, user_nicename FROM `default_posts` as `dp`, `default_terms` as `dt`, `default_term_relationships` as `dtr`,`default_users` as `du` where `dp`.`post_author`=`du`.`ID` and `dp`.`ID`=`dtr`.`object_id` and `dtr`.`term_taxonomy_id`=”.$cat_id.”;”);

$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 $author ) {
$author = get_userdata( $author->ID );
$posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
$name = $author->display_name;

if ( $show_fullname && ($author->first_name != ” && $author->last_name != ”) )
$name = “$author->first_name $author->last_name”;

if ( !($posts == 0 && $hide_empty) )
$return .= ‘

  • ‘;
    if ( $posts == 0 ) {
    if ( !$hide_empty )
    $link = $name;
    } else {
    $link = ‘ID, $author->user_nicename) . ‘”‘;

    if ( !empty($feed) ) {
    $title = ‘ title=”‘ . $feed . ‘”‘;
    $alt = ‘ alt=”‘ . $feed . ‘”‘;
    $name = $feed;
    $link .= $title;
    }

    $link .= ‘>’;

    if ( !empty($feed_image) )
    $link .= “‘;
    else
    $link .= $name;

    $link .= ‘‘;

    if ( empty($feed_image) )
    $link .= ‘)’;
    }

    if ( $optioncount )
    $link .= ‘ (‘. $posts . ‘)’;

    }

    if ( !($posts == 0 && $hide_empty) )
    $return .= $link . ‘

  • ‘;
    }
    if ( !$echo )
    return $return;
    echo $return;
    }
    ?>

    [/sourcecode]

    And then to call, just define the category you want:

    [sourcecode lang="php"]

    $cat=0;
    if (have_posts()){    //get the present category, if there is one
    if (is_category()) {
    $cat = get_query_var('cat');
    }
    }
    if($cat!=0){
    ?>

    Authors:

    [/sourcecode]

    Share and Enjoy

    • Facebook
    • Twitter
    • Delicious
    • LinkedIn
    • StumbleUpon
    • Add to favorites
    • Email
    • RSS
    Posted in codeRelease, PHP, Software, wordpress Tagged , , , , , , Comments Off

    Comments are closed.