首页 > 解决方案 > Wordpress 如何将自定义类添加到作者名称以进行样式设置

问题描述

我在下面有这段代码可以在帖子标题下显示作者姓名,但是我如何为它分配一个类,以便我可以使用 css 更改它的样式,比如它的颜色和字体大小等?

<?php the_author_posts_link(); ?>

标签: phphtmlcsswordpressstyles

解决方案


the_author_posts_link 实际上回显了这种形式的锚标记

<a href="https://somewebsite.com/author/john-smith/" title="Posts by john.smith" rel="author">John.Smith</a>

最简单的格式化方法可能是将它包装在一个 div 中,它有一个独特的类,您可以在 Wordpress 后端的 Appearance>Cusomize 中设置它的样式

<div class="myAuthorStyle"><?php the_author_posts_link(); ?></div>

一个简单的样式示例:

.myAuthorStyle a {
  color: magenta;
  text-decoration: none;
  font-size: 2em;
  display: inline-block;
}
<div class="myAuthorStyle"><a href="https://somewebsite.com/author/john-smith/" title="Posts by john.smith" rel="author">John.Smith</a></div>


推荐阅读