Created
March 23, 2014 04:37
-
-
Save manchumahara/9718860 to your computer and use it in GitHub Desktop.
Wordpress default archive widget doesn't have any option for showing author archive widget. This small code snippet will convert default archive widget into a author archive widget. For showing the link I hooked only for month link, same filter can be applied to other archive link for day or year archive link for any author. This works on author…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('getarchives_where', 'getarchives_where_author'); | |
add_filter('month_link', 'month_link_author'); | |
/** | |
* Custom function to filter query for author archive widget, this works on author page only | |
* | |
* @param $where | |
* @return string | |
*/ | |
function getarchives_where_author($where){ | |
global $wpdb, $wp_locale; | |
if(is_author()){ | |
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); | |
//var_dump($curauth); | |
$where .= ' AND post_author = '.$curauth->ID.' '; | |
} | |
return $where; | |
} | |
/** | |
* Custom function to filter author archive link for month | |
* | |
* @param $link | |
* @return string | |
*/ | |
function month_link_author($link){ | |
global $wpdb, $wp_locale; | |
if(is_author()){ | |
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); | |
//author_name=asaduzzeman | |
if(strpos($current_url, '?') !== false) { | |
$link .= '&author_name='.$curauth->user_login; | |
} | |
else{ | |
$link .= '?author_name='.$curauth->user_login; | |
} | |
} | |
return $link; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This throws errors b/c $current_url is not set. But even if you set it, it doesn't work.