Wordpress 列出按姓氏排序的作者
好的,当我得到按姓氏排序的页面时,我将共享整个代码。我已经将我的作者页面设置为显示作者图片网站和twitter链接,如果用户没有在管理员中填写,则将其隐藏。我也有网页显示姓氏,名字,但网页是按名字排序的,因此看起来很可怕。我试过几次说服我的客户不要这样做,但她已经准备好了。我花了很长时间在这上面,需要一些帮助。。。在windows服务器上使用Wordpress将是我的死亡,我要说的就是这么多。这是我知道导致问题的代码:Wordpress 列出按姓氏排序的作者,wordpress,author,Wordpress,Author,好的,当我得到按姓氏排序的页面时,我将共享整个代码。我已经将我的作者页面设置为显示作者图片网站和twitter链接,如果用户没有在管理员中填写,则将其隐藏。我也有网页显示姓氏,名字,但网页是按名字排序的,因此看起来很可怕。我试过几次说服我的客户不要这样做,但她已经准备好了。我花了很长时间在这上面,需要一些帮助。。。在windows服务器上使用Wordpress将是我的死亡,我要说的就是这么多。这是我知道导致问题的代码: ` <?php function contributor
`
<?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 ", "; 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(); ?>`
`
为什么不使用新的WP_User_Query();将您的角色改为“贡献者”?这比你在上面做的要干净得多
再看看这个:我非常接近,我用新代码编辑了我的代码。问题是当我删除foreach循环时,我只得到了管理员,并且出于某种原因,他在他的帖子计数中拥有所有帖子。我尝试了一个var_转储($author->ID);但当我删除foreach循环中的所有内容时,这并没有起到任何作用。