如何在 WordPress 中的 Post 标题之上添加标题

How to add title on top of Post title in WordPress

我想在所有帖子的标题之上添加一个附加到 URL 的标题。如何使用 CSS 或 Jquery?

实现它

具体参考下图

https://i.imgur.com/qKPwrvZ.png

这可以通过多种方式实现,

  1. 您可以安装插件 ACF 添加 post 元字段到每个 post

  2. 在您的主题文件中打开 index.php 或打开您获取所有 post 的模板文件。

    **

    确保将代码粘贴到文件中的适当位置,确保将其粘贴到此行之后:

     <?php while ( have_posts() ) : the_post(); ?>
    
     And before:
    
     <?php endwhile; // end of the loop. ?>
    
     Use the following snipped to embed the metadata, changing the class name, field name and HTML formatting as required.
    
     <p class="myfieldname"><?php the_field('Field_Name'); ?></p>
    
     Save the file, and head to your site’s front-end to review.
    

**

下面是我是如何做到的。

  1. 我找到了单个 posts (single.php) 的模板部分。这是负责 post 上所有内容格式的模板。

  2. 我找到了条目标题(post标题)所在的位置。

  3. 我创建了一个 div class 的标题,我想在 post 标题(条目标题)上添加。

  4. 我在创建的新标题中添加了一个 link。所以看起来像这样

  5. 创建 div class 的原因是让我能够将 CSS 添加到 class 而不会干扰 entry-title class.

  6. 现在我添加了 CSS,它看起来很完美,就像我想要的那样