douhong4452 2014-02-06 15:08
浏览 163
已采纳

在WordPress中的作者存档页面上获取作者姓名

I am making template for archives in WordPress website, but my template will not work for author name on author archive.

I have this:

<?php if (is_category('')) { ?>
<?php single_cat_title(); ?>

<?php } elseif (is_author('')) { ?>
<?php get_userdata( get_query_var('author') );?>

<?php } elseif (is_day('')) { ?>
<?php echo get_the_time('F j, Y'); ?>

<?php } elseif (is_month('')) { ?>
<?php echo get_the_time('F Y'); ?>

<?php } elseif (is_year('')) { ?>
<?php echo get_the_time('Y'); ?>

<?php } elseif (is_tag('')) { ?>
<?php echo single_tag_title(''); ?>
<?php } ?>

This part will not work:

<?php } elseif (is_author('')) { ?>
<?php get_userdata( get_query_var('author') );?>
  • 写回答

2条回答 默认 最新

  • doumu4032 2014-02-06 15:19
    关注

    The function you're using in is_author returns a user object. It doesn't output anything.

    Correct usage would be:

    <?php 
    // Get current author.
    $curauth = ( get_query_var( 'author_name' ) ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) ); ?>
    
    Author: <?php echo $curauth->nickname; ?>
    

    Also the empty string isn't necessary with is_category etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入