我在每个页面模板上都有一个作者列表。此作者列表显示了作者的详细信息和照片。我还在不同页面模板的许多不同位置显示作者图像。在我改变获取作者详细信息的方式之前,这种用法一直很有效。
我又回到了我使用的旧方法,但我的作者图片没有显示出来。它在作者列表中仍然有效,但模板页面上的图像显示错误变量currentauth不存在。
我错过了什么?
调试信息:
注意:wp内容/主题/电子邮箱/单项目发布。php:81-未定义变量:curauth
注意:wp内容/主题/电子邮箱/单项目发布。php:81-尝试获取非对象的属性
注意:wp内容/主题/电子邮箱/单项目发布。php:82-未定义变量:curauth
注意:wp内容/主题/电子邮箱/单项目发布。php:82-尝试获取非对象的属性-
AUTHOR\\u列表:
<div class="author-list">
<div class="author-list-inner">
<?php
// Get the authors from the database ordered randomly
global $wpdb;
$auth_query = "SELECT ID, user_nicename from $wpdb->users WHERE ID != \'1\' ORDER BY \'ASC\' LIMIT 20";
$author_ids = $wpdb->get_results($auth_query);
// Loop through each author
foreach($author_ids as $author) :
// Get user data
$curauth = get_userdata($author->ID);
// Get link to author page
$user_link = get_author_posts_url($curauth->ID);
$post_link = get_permalink($curauth->ID);
// Set default avatar (values = default, wavatar, identicon, monsterid)
$main_profile = get_the_author_meta(\'mainProfile\', $curauth->ID);
$hover_profile = get_the_author_meta(\'hoverProfile\', $curauth->ID);
$award_profile = get_the_author_meta(\'awardProfile\', $curauth->ID);
?>
<div class="da-author">
<div class="original-image">
<img src="<?php echo $main_profile; ?>" alt="<?php echo $curauth->display_name; ?>">
</div>
<div class="hover-image">
<a href="<?php echo $user_link; ?>">
<img src="<?php echo $hover_profile; ?>">
</a>
</div>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
</div>
PAGE\\u模板:
<div id="projects-single" class="<?php if (get_field(\'awards\')): ?> award-winner <?php endif; ?> js-height">
<div class="author-container hide-for-medium-down start-closed">
<?php get_template_part( \'author_list\' ); ?>
</div>
<div class="small-12 large-12 columns">
<?php while(have_posts()): the_post(); ?>
<div class="large-set">
<header>
<h2><?php the_title(); ?></h2>
<?php if (get_field(\'awards\')): ?>
<h3><?php the_field(\'award_title\'); ?></h3>
<?php endif; ?>
<div id="author-meta" class="show-for-small-only">
<p><?php the_author_posts_link(); ?> was involved with <?php the_title(); ?></p>
</div>
</header>
<div class="show-for-small-only">
<hr>
</div>
<div class="entry-content">
<?php the_content(); ?>
</div>
<div class="author-set hide-for-small">
<div class="author-project-image">
<img src="<?php echo get_the_author_meta(\'mainProfile\', $curauth->ID); ?>" class="no-award">
<img src="<?php echo get_the_author_meta(\'awardProfile\', $curauth->ID); ?>" class="award">
</div>
<div class="author-project-blurb">
<h3><?php the_author_posts_link(); ?></h3>
<p>I was part of the design team on the <?php the_title(); ?> project.</p>
</div>
</div>
</div>
</article>
<?php endwhile; ?>
</div>
</div>
这是我展示图像的部分:
<img src="<?php echo get_the_author_meta(\'mainProfile\', $curauth->ID); ?>" class="no-award">
<img src="<?php echo get_the_author_meta(\'awardProfile\', $curauth->ID); ?>" class="award">