Categories
Wordpress

Add author bio with social links to blog post

Often we like to add a author bio at the bottom of blog post. To do so we use external plugins. By adding few script to our theme function file we can easily create our own custom author bio for our blog post. Lets see what type of field we need to get user/author social links:

author links field screenshot

What we need to add in function file:

<?php
if ( is_admin() ) {
    add_filter('user_contactmethods', 'author_bio_social_links');

    function author_bio_social_links( $data ){
        $data['author_twitter_url'] = __( 'Twitter', 'msbd-theme' );
        $data['author_facebook_url'] = __( 'Facebook', 'msbd-theme' );
        $data['author_github_url'] = __( 'Github', 'msbd-theme' );
        $data['author_wp_url'] = __( 'Wordpress', 'msbd-theme' );

        return $data;
    }
}
?>

[manage_adv size=”responsive” sponsor=”amazon” type=”image”]

Now we will show the author bio with the social links we have added to admin section:

Share with:

Categories
Wordpress

Get the authors list who submitted highest number of posts in wordpress

Now a days the use of wordpress content management system is not limited to a blog or a portfolio website, it is also used as a eCommerce website platform. No matter how we use it, we often need the highest post submitted author list. Using below script you can get the list of authors who submitted highest number of posts in WordPress.

<?php
    function top_authors_list($number = 10) {
        $html = '';
        $uc = array();
        $blogusers = get_users();

        if ($blogusers) {
            $html .= '<ul>';
            foreach ($blogusers as $bloguser) {
                $post_count = count_user_posts($bloguser->ID);
                $uc[$bloguser->ID] = $post_count;
            }
            arsort($uc);

            $i = 0;
            foreach ($uc as $key => $value) {
                $i++;
                if ($i <= $number) {
                    $user = get_userdata($key);
                    $author_posts_url = get_author_posts_url($key);
                    $post_count = $value;
                    if ($post_count > 0) {
                        $html .= '<li><a href="' . $author_posts_url .'">' . $user->display_name . '</a> (' . $post_count . ')</li>';
                    }
                }
            }
            $html .= '</ul>';
        }

        return $html;
    }
?>

 

 

Share with: