• Maxaud

    (@maxaud)


    I’m trying to make a blog where I can allow users to upload avatars and have them show up in the sidebard linked to their profile. It also has links to their website and their name.

    It can be viewed in the sidebar at http://www.themortgagesalesblog.com/home
    **only on the home page

    the code I placed in my sidebar is:

    <div class="bottombar"><h2 class="widgettitle">Contributors:</h2>
    	<ul>
        		<?php
    			$order = 'user_nicename';
    			$user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY $order"); // query users
    				foreach($user_ids as $user_id) : // start authors' profile "loop"
    			$user = get_userdata($user_id);
    		?>
    		<li>
    			<table>
    				<tr>
    					<td>
    						<a href="/home/authors/<?php echo $user->user_nicename; ?>" alt="<?php echo $user->nickname; ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/authors/<?php echo $user->last_name; ?>.jpg" alt="<?php echo $user->nickname; ?>" border="1" /></a>
    					</td>
    					<td>
    						<?php echo '<a href="' . $user->user_url . '">' . $user->display_name . '</a>'; ?><br />
    						<?php echo '<a href="' . $user->user_url . '">View Website</a>'; ?><br />
    						<a href="/home/authors/<?php echo $user->user_nicename; ?>" alt="<?php echo $user->nickname; ?>">Profile</a>
    					</td>
    				</tr>
    			</table>
    		</li>
    		<?php	endforeach;
    			// end of authors' profile 'loop'
    		?>
    	</ul>
    </div>

    I tried making this into a widget using the following code:

    <?php
    /*
    Plugin Name: Contributors Widget
    Description: A widget that ads the Contributors to the sidebar. Works with Author-Image to display the users uploaded avatar.
    Author: Dustin Dempsey
    Version: 1
    Author URI: http://www.playforwarddesigns.com
    */
    
    function widget_contributor_init() {
        if (!function_exists("register_sidebar_widget")) {
    	return;
        }
    
    function widget_contributor($args) {
        extract($args);
    ?>
            <?php echo $before_widget; ?>
                <?php echo $before_title
                    . 'Contributors::'
                    . $after_title; ?>
    
    	<ul>
        		<?php
    			$order = 'user_nicename';
    			$user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY $order"); // query users
    				foreach($user_ids as $user_id) : // start authors' profile "loop"
    			$user = get_userdata($user_id);
    		?>
    
    		<li>
    			<table>
    				<tr>
    					<td>
    						<img src="<?php bloginfo('stylesheet_directory'); ?>/images/authors/<?php echo $user->last_name; ?>.jpg" alt="<?php echo $user->nickname; ?>" border="1" />
    					</td>
    					<td>
    						<?php echo '<a href="' . $user->user_url . '">' . $user->display_name . '</a>'; ?><br />
    						<?php echo '<a href="' . $user->user_url . '">View Website</a>'; ?><br />
    						<a href="/home/authors/<?php echo $user->user_nicename; ?>" alt="<?php echo $user->nickname; ?>">Profile</a>
    					</td>
    				</tr>
    			</table>
    		</li>
    
    		<?php	endforeach;
    			// end of authors' profile 'loop'
    		?>
    	</ul>          
    
            <?php echo $after_widget; ?>
    <?php
    }
    register_sidebar_widget('Contributors',
        'widget_contributor');
    }
    
    add_action("plugins_loaded", "widget_contributor_init");
    
    ?>

    It keeps getting an error.
    Could anyone show me what I did wrong?

    Also, in the example how could I change the display order by either a random order or by the people that posts the most show up first?

    Thanks in advance. Much appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Maxaud

    (@maxaud)

    anyone at all?

    What about restricting it to show only those that are authors as it shows subscribers too.

    Thanks, your template code helped me some today 🙂

    To get 1 random users I used this

    $user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY rand() LIMIT 1"); // query users

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘convert code to widget (author avatars on sidebar)’ is closed to new replies.