Wordpress-将自定义字段输出为ul列表 [英] Wordpress - output custom field as ul list

查看:58
本文介绍了Wordpress-将自定义字段输出为ul列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义字段,其内容我想作为ul列表输出。

I have a custom field who's content I would like to output as a ul list.

自定义字段包含用空格分隔的单词。

The custom field contains words that are separated with spaces.

我试图在此处使用此代码,但无法正常工作。

I'm trying to use this code here but it's not working.

    <?php
    $list_items = get_post_meta($post->ID, 'idid');

         if($list_items){
            $list_items = explode(" ", $list_items) {
                echo '<ul>';
                    foreach($list_items as $list_item)
                        echo '<li>' . $list_item . '</li>';
                echo '</ul>';
            }
        }

    ?>


推荐答案


  • 1-添加; 爆炸功能之前,并删除赞誉。

  • 2-声明第二个变量,该变量不同于 $ list_items
    爆炸结果放在何处。

  • 3- get_post_meta()的第二个参数应该是自定义字段的子项(在您的情况下,它是idid ?),还添加true参数。

    • 1- add ; before explode function, and remove accolades.
    • 2- declare a second variable different than $list_items where to put result of explode.
    • 3- second parameter of get_post_meta() should be the slug of your custom field (in your case is it idid?), add also true parameter.
    • 您的代码应如下所示:

          <?php
          $list_items = get_post_meta($post->ID, 'idid', true);
      
               if($list_items){
                  $list_items2 = explode(" ", $list_items);
                      echo '<ul>';
                          foreach($list_items2 as $list_item)
                              echo '<li>' . $list_item . '</li>';
                      echo '</ul>';
      
              }
      
          ?>
      

      这篇关于Wordpress-将自定义字段输出为ul列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆