我正在为 WordPress 网站中的文件制作模板,但我的模板不适用于作者文件中的作者姓名。
我有这个:
<?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 } ?>
这部分将不起作用:
<?php } elseif (is_author('')) { ?>
<?php get_userdata( get_query_var('author') );?>
最佳答案
WordPress 支持一个存档模板。您只需添加一个 author.php
文件到您的主题文件夹:http://codex.wordpress.org/Author_Templates
并且您可以使用所有作者功能,例如:
get_the_author()
作者姓名get_the_author_meta('description')
用于说明 get_avatar( get_the_author_meta('ID'), 40 )
用于头像 顺便说一下,还有类别 ( http://codex.wordpress.org/Category_Templates ) 和标签 ( http://codex.wordpress.org/Tag_Templates ) 的文件。
关于php - 在 WordPress 中的作者存档页面上获取作者姓名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21606565/