dougu4448 2015-09-21 04:17
浏览 45
已采纳

每行上的WordPress元框输出

Ive been looking for a way I can take a WordPress custom meta box's content that is entered on each line and output said contents on each line instead of in a single line, example:

Mon
Tues
Wed
Thurs
Fri
Sat
Sun

The above days of the week are entered in a custom meta box and I can output the contents of the meta box in my single.php with:

<?php if ( 'custom_post_type' == get_post_type() ) :
    $foobar_meta = get_post_meta( get_the_ID(), 'meta-textarea', true );
    if( !empty( $foobar_meta ) ) : ?>
        <div class="jedi">
            <ul id="workload">
                <li><?php echo $foobar_meta; ?></li>
            </ul>
        </div>
    <?php endif; ?>
<?php endif; ?>

However when I run the code it outputs as: <li>Mon Tues Wed Thurs Fri Sat Sun</li>. How can I target everything that is entered on a line and output individually as:

<li>Mon</li>
<li>Tues</li>
<li>Wed</li>
<li>Thurs</li>
<li>Fri</li>
<li>Sat</li>
<li>Sun</li>

Per my research I assume I would use an array() with a foreach but targeting each line I am having difficulties in what to use to call the meta box to run through. I did look on the codex but I didn't see anything on how to target what I need. So how can I with PHP take content that is entered on a single line and display it's look on the site?

  • 写回答

1条回答 默认 最新

  • dongmeng2687 2015-09-21 04:52
    关注

    Please see below code this may help you:

    $string_arr = explode("
    ", $foobar_meta);
    $newstring = '<ul id="workload">';
    foreach($string_arr as $single_string)
    {
        $newstring .= '<li>' . $single_string . '</li>';
    }
    $newstring .= '</ul>';
    echo $newstring;
    

    OR

    You can use like this too $newstring .= '<li>' . str_replace(" ", '</li><li>', $single_string) . '</li>'; without loop and explode.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型