列表作者按last_name排序

时间:2013-05-23 23:28:23

标签: wpdb author

好的,所以当我按照姓氏订购页面时,我会分享整个代码。我已经设置了我的作者页面来显示作者图像网站和Twitter链接,如果用户没有在管理员中填写它,则隐藏它们。我还有显示last_name,first_name的页面,但页面按名字排序,因此看起来很糟糕。我曾多次尝试过谈论我的客户,但她已经准备好了。我已经花了很长时间在这上面并且需要一些帮助......在Windows服务器上工作Wordpress将会让我感到恶心。这是我知道导致问题的代码:

    `
   <?php
function contributors() {
global $wpdb;
$user_post_count = count_user_posts( $userid );
$authors = $wpdb->get_results("SELECT DISTINCT * FROM wp_users u LEFT JOIN wp_usermeta um ON u.ID = um.user_id WHERE um.meta_key = 'last_name' ORDER BY um.meta_value ASC;");

foreach ($authors as $author) {
if (get_usernumposts($author->ID) >= 1){
echo "<li>";
echo "<a href=\"".get_bloginfo('url')."/author/";
the_author_meta('user_nicename', $author->ID);
echo "/\">";
echo the_author_image($author->ID);
echo "</a>";
echo "<br />";
echo '<div>';
echo "<h2><a href=\"".get_bloginfo('url')."/author/";
the_author_meta('user_nicename', $author->ID);
echo "/\">";        
$last_name = get_the_author_meta('last_name', $author->ID);
if ($last_name != null):
the_author_meta('last_name', $author->ID);endif;
$first_name = get_the_author_meta('first_name', $author->ID);
if ($first_name != null):
echo ",&nbsp;"; endif;
the_author_meta('first_name', $author->ID); 
echo ' (' . count_user_posts( $author->ID ) . ')'; 
echo "</a></h2>";
echo "<br />";

// Position/Title of Authors
$position = get_the_author_meta('position', $author->ID);
if ($position != null):?>
<p class="user_cust"><?php echo $position ?></p><?php endif; ?>
<?php
$user_url = get_the_author_meta('user_url', $author->ID);
if ($user_url != null):?>
<p class="user_cust"><a href="<?php echo $user_url ?>" target="_blank">Linkedin Profile</a></p><?php endif; ?>
<?php
echo "</div>";
echo "</li>";
}
}
}
/**
 * Template Name: Author's Page
 * The template for displaying WP_AUTHOR_LIST.
 *
 * Used to display Author's Details on a page.
 * 
 */
?>
<?php get_header(); ?>
<div id="content" class="page">
    <?php include('scroll_to.php'); ?> 
  <div class="page-wrapper">
    <h2>Authors</h2>
<?php get_template_part( 'loop', 'authors' ); ?>
    <!-- /* Begin Author's Page */ -->
    <div id="authorlist">

      <ul>
        <?php contributors(); ?>
      </ul>

    </div>
    <!-- /* End Author's Page */ -->
  </div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>`

1 个答案:

答案 0 :(得分:0)

为什么不使用新的WP_User_Query();而将你的角色设置为“贡献者”而不是?它比你上面做的要干净得多。

另请注意:https://wordpress.stackexchange.com/questions/30977/list-users-by-last-name-in-wp-user-query