maxaud
March 28th, 2008, 04:36 PM
I'm working wordpress trying to make a sidebar widget.
The following code works fine if entered directly into the sidebar template file.
If I make a seperate plugin/widget so it can be easily moved around within the sidebar from the wordpress CP I get the following error:
Fatal error: Call to a member function on a non-object
My code is as follows:
<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>
<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>
<?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>
</li>
<?php endforeach;
// end of authors' profile 'loop'
?>
</ul>
Any help would be greatly appreciated.
Also, how could I change the sort order to be random?
Thanks!
The following code is my widget.
It stated that the error was on line 26.
<?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; ?>
<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>
<?php echo $after_widget; ?>
<?php
}
register_sidebar_widget('Contributors',
'widget_contributor');
}
add_action("plugins_loaded", "widget_contributor_init");
?>
The following code works fine if entered directly into the sidebar template file.
If I make a seperate plugin/widget so it can be easily moved around within the sidebar from the wordpress CP I get the following error:
Fatal error: Call to a member function on a non-object
My code is as follows:
<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>
<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>
<?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>
</li>
<?php endforeach;
// end of authors' profile 'loop'
?>
</ul>
Any help would be greatly appreciated.
Also, how could I change the sort order to be random?
Thanks!
The following code is my widget.
It stated that the error was on line 26.
<?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; ?>
<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>
<?php echo $after_widget; ?>
<?php
}
register_sidebar_widget('Contributors',
'widget_contributor');
}
add_action("plugins_loaded", "widget_contributor_init");
?>