是否可以仅显示作者的姓名和描述(又称beio) 如果 描述包含文字?

此代码不起作用(它不返回名称或描述),但希望可以编辑它以实现此目标:

<?php
$authorDesc = the_author_meta($post->ID, 'description', true);
if (!empty($authorDesc)) {
?>
<em>by <?php the_author(); ?></em>
<span><?php the_author_meta('description'); ?></span>
<?php } ?>
有帮助吗?

解决方案

<?php
$authordesc = get_the_author_meta( 'description' );

if ( ! empty ( $authordesc ) )
{
?>
    <a href="<?php
    echo get_author_posts_url( get_the_author_meta( 'id' ) );
    ?>"><?php
    the_author();
    ?></a>
    <?php
    echo wpautop( $authordesc );
}

其他提示

首先,您需要使用 get_the_author_meta 代替 the_autho_meta$authorDesc (get_the_author_meta 返回值, the_author_meta 显示它)。

其次,您需要使用 user_description 作为两个函数的论点 description.

希望它有效。

编辑 - 这里 是文件 the_author_meta 有关更多信息。编辑2-您也不需要声明$ post-> id为第一个参数 the_author_meta. 。您在循环中使用它吗?

许可以下: CC-BY-SA归因
scroll top