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 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度