【问题标题】:Wordpress Text is not Shows line by lineWordpress 文本不逐行显示
【发布时间】:2012-02-11 18:25:00
【问题描述】:

我为 wordpress 编写了一个自定义类型,其中包含一个文本区域。我可以保存它,也可以从单一视图访问。但是如果作者逐行保存,我想逐行显示它们。但它不是逐行显示它们,而是将它们全部显示为一行。

这是我的 single.php 的自定义元显示代码;

             <div id="yemek_resim">
                    <?php if($tz_image_display == 'true') : ?>

                    <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) : /* if post has post thumbnail */ ?>

                    <?php the_post_thumbnail('single-large'); ?>

                    <?php endif; ?>

                    <?php endif; ?>
                    </div><!-- yemek_resim -->
        <div id="yemek_malzemeleri">
        <?php
        $malzemeler = get_post_meta($post->ID, 'ofa_yemek_malzemeler', true);
        echo esc_attr($malzemeler);
        ?>
        </div><!-- yemek_malzemeleri -->

这里 yemek_malzemeler 的内容来自文本区域,作者可以编写多行内容。但在现场,它们似乎是一条线......

【问题讨论】:

  • 你能展示输出和预期输出的例子吗? Wordpress 的文本编辑器有自己的换行方式。
  • 我没有使用 wordpress 的文本编辑器,我使用的是自定义元框和 html5 textarea 字段。

标签: php html css wordpress


【解决方案1】:

您应该在输出文件中使用 N2BR PHP 函数。只需在 Wordpress 的 single.php 文件中写入 &lt;?php echo n2br($string); ?&gt;。祝你好运;)

【讨论】:

  • 现在我试过了,但现在看起来像这样,asd
    dasf
    asdf
    asdf
    asd
    fasd
    f
    asdf asdfadf
  • 好的,然后在输出文件上应用 n2br,其中应该显示文本。并将其从操作文件中删除。
  • 我在输出文件上应用了,但是如何从操作文件中删除它?
  • 你最初把n2br贴在哪里了?我以为你在你的动作文件上做了,它在&lt;form method="post" action="THE_ACTION_FILE.php"&gt;中使用
  • 只应用在single.php文件上
【解决方案2】:

我通过使用&lt;pre&gt; &lt;/pre&gt; 标签解决了这个问题。感谢您的关心。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多