好的,所以当我按姓氏订购页面时,我将分享整个代码。我已经设置了我的作者页面来显示作者图片网站和 twitter 链接,如果用户没有在管理员中填写,则隐藏它们。我也有显示姓氏、名字的页面,但页面是按名字排序的,因此看起来很糟糕。我多次尝试说服我的客户不要这样做,但她已经准备好了。我在这方面花了很长时间,需要一些帮助......在 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 ", "; 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(); ?>`