【问题标题】:Default Paragraph Class in Wordpress the_contentWordpress 中的默认段落类 the_content
【发布时间】:2013-02-26 00:43:31
【问题描述】:

我确信这很简单,但我在 Google 上搜索了大约 30 分钟,但没有成功。我想知道是否可以调整 Wordpress 中 the_content 输出的默认段落类。

我了解到您可以将过滤器添加到主题的 functions.php 文件中,但是 WordPress 的这种特殊用途并未使用主题。考虑一个静态 HTML 站点(5 页),每个页面上都有一个主要内容区域。 Wordpress 仅用于通过客户编辑任何必要的 5 个帖子来更改这 5 个内容区域的内容。

问题是 WordPress 吐出的 p 标签没有应用任何类。我可以在我的查询或任何东西中更改它吗?理想情况下,我可以单独更改每个页面上输出的段落类。

想法?

提前感谢您的帮助!

【问题讨论】:

    标签: css wordpress paragraph


    【解决方案1】:

    用 div 包装你的内容,并为其应用一个类:

    <div class="content">
        <? the_content(); ?>
    </div>
    

    并像这样设置样式:

    .content p { ... }
    /* Page-specific */
    .page-id-1 .content p { ... }
    

    【讨论】:

      【解决方案2】:

      接受的答案并没有真正为我回答问题,但我找到了 this post,它给了我我需要的东西——所以我的解决方案最终是这样的:

      <?php
      $content = get_content();
      $content = str_replace('<p', '<p class="default-class"', $content); ?>
      
      <div class="wrapper"><?php echo $content ?></div>
      

      成功了!

      【讨论】:

      • 您的代码中有错误。 1) $content = get_content(); - $content = get_the_content();
      【解决方案3】:
      function wph_add_class_for_p_tag($content) {
          $content = str_replace('<p>', '<p class="SomeClass">', $content);
          return $content;
      }
      
      add_filter('the_content', 'wph_add_class_for_p_tag', 9999);
      add_filter('the_excerpt', 'wph_add_class_for_p_tag', 9999);
      

      【讨论】:

      猜你喜欢
      • 2022-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-04
      • 2019-07-06
      • 2015-05-09
      • 2010-11-23
      • 1970-01-01
      相关资源
      最近更新 更多