【问题标题】:Wordpress how to add a custom class to Author name for styling purposesWordpress 如何将自定义类添加到作者名称以进行样式设置
【发布时间】:2021-11-13 15:28:19
【问题描述】:

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

<?php the_author_posts_link(); ?>

【问题讨论】:

  • 嗨,我已经给出了答案,但总的来说,使用浏览器的开发工具检查工具来查看元素会很有用。这样你就可以准确地看到 Wordpress 函数在你的页面上添加了哪些代码(我发现 Wordpress Codex 并不清楚它是仅输出 URL 还是完整的锚元素,结果是后者)。跨度>

标签: php html css wordpress styles


【解决方案1】:

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;
}
&lt;div class="myAuthorStyle"&gt;&lt;a href="https://somewebsite.com/author/john-smith/" title="Posts by john.smith" rel="author"&gt;John.Smith&lt;/a&gt;&lt;/div&gt;

【讨论】:

    猜你喜欢
    • 2019-09-14
    • 2021-06-12
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 1970-01-01
    • 2015-06-29
    • 1970-01-01
    • 2018-07-15
    相关资源
    最近更新 更多