【问题标题】:why are two paragraphs being added on wordpress custom excerpt function used?为什么在使用的 wordpress 自定义摘录功能上添加了两个段落?
【发布时间】:2021-01-14 06:38:27
【问题描述】:

我正在尝试开发 wordpress 网站,我在前端使用自定义摘录功能来显示我的帖子内容。代码如下:

<h5 class="post-title"><a href=" <?php the_permalink() ?> "> <?php the_title() ?> </a></h5>
<?php the_post_thumbnail('home') ?>
<p class="content excerpt"> <a href="<?php the_permalink() ?>"> <?php news_excerpt(25) ?> </a></p><hr />

但是,问题是在浏览器输出中添加了两个显示段落的内容。输出如下:

<p class="content excerpt"> <a href="http://localhost/wordpress/index.php/2021/01/11/%e0%a6%9f%e0%a6%bf%e0%a6%95%e0%a6%be-%e0%a6%aa%e0%a7%87%e0%a6%a4%e0%a7%87-%e0%a7%a8%e0%a7%ac-%e0%a6%9c%e0%a6%be%e0%a6%a8%e0%a7%81%e0%a7%9f%e0%a6%be%e0%a6%b0%e0%a6%bf-%e0%a6%a5%e0%a7%87%e0%a6%95/"> <!-- wp:paragraph -->
<p>চলতি মাসের ২১ থেকে ২৫ তারিখের মধ্যে দেশে করোনাভাইরাসের টিকা আসবে। আর এই টিকা দেওয়া শুরু হবে ফেব্রুয়ারির প্রথম সপ্তাহে। এ জন্য নিবন্ধন </a></p>

我该如何解决这个问题? 谢谢。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    使用此功能对内容进行段落操作: wpautop(string $pee, bool $br = true)

    https://developer.wordpress.org/reference/functions/wpautop/

    【讨论】:

    • 谢谢,remove_filter('the_content', 'wpautop') 不起作用,我实际上是在说 the_content() 模板标签的默认包装

      标签。请解释一下,@MANOJ VASHIST

    • 通过将以下内容添加到您的 functions.php 文件中来停止此操作 remove_filter('term_description','wpautop');
    【解决方案2】:

    最后,我自己开发了一个解决这个问题的方法。如下:

    function my_content() 
    {
        echo trim(strip_tags(get_the_content()));
    }
    
    function get_my_content()
    {
        return trim(strip_tags(get_the_content()));
    }
    

    对我来说效果很好。 谢谢大家。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-19
      • 2016-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多