php - 在 wordpress 中设置 php 生成的链接样式

标签 php css wordpress

我的 wordpress 循环中有以下代码来显示置顶帖子:

<div class="blogpost">
<?php // div class for styling sticky posts on main page. ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>

    <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

    <?php the_excerpt(); // Show summary of posts only. ?>
</div> <!-- end class sticky -->
</div> <!-- end class blogpost -->

我想用 CSS 设置 h2 的样式,但我无权访问它。当我查看 firebug 中的代码时,它看起来像这样:

<div class="blogpost">
<div id="post-324" class="post-324 post type-post status-publish format-standard sticky hentry category-uncategorized" <h2="">

    <a href="http://mydomain.com/wordpress/?p=324">Headline of post </a>
    ...
</div>
</div>

有谁知道我必须更改什么才能让我的标题 h2 变成 a?谢谢!

最佳答案

第一个代码块缺少一个 ><?php post_class(); ?> 之后.因此,您应该能够设置 h2 的样式一旦修复。

如果你想要 h2a里面,你可以把它放在里面:

<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><h2><?php the_title(); ?></h2></a>

关于php - 在 wordpress 中设置 php 生成的链接样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12806108/

相关文章:

html - 我可以只为 div 的背景图像设置不透明度吗?

mysql - WordPress 媒体上传数据库错误重复条目

php - Woocommerce 电子邮件订单详细信息中的其他列和项目值

php - WordPress 代码仅显示 1 个帖子

php - 图表比谷歌图表更好?

CSS 中间 div 高度

jquery - float 元素不能正确 float

php - 正则表达式仅剥离标签

php - 从第二个表中获取总值(value)并将其显示在表中

html - 某些 Bootstrap 4 类在我的 Angular 8 元素中不起作用