Display all Categories

时间:2021-12-05 作者:gimsech

我使用此选项显示所有类别:

<?php $args = array(
    \'child_of\'            => 0,
    \'current_category\'    => 0,
    \'depth\'               => 0,
    \'echo\'                => 1,
    \'exclude\'             => \'\',
    \'exclude_tree\'        => \'\',
    \'feed\'                => \'\',
    \'feed_image\'          => \'\',
    \'feed_type\'           => \'\',
    \'hide_empty\'          => 1,
    \'hide_title_if_empty\' => false,
    \'hierarchical\'        => true,
    \'order\'               => \'ASC\',
    \'orderby\'             => \'name\',
    \'separator\'           => \' \',
    \'show_count\'          => 0,
    \'show_option_all\'     => \'\',
    \'style\'               => \'h3\',
    \'taxonomy\'            => \'category\',
    \'title_li\'            => __( \'Categories\' ),
    \'use_desc_for_title\'  => 1,
); 

var_dump( wp_list_categories($args) );  ?>
但它也给了我一个词;空;。

enter image description here

如何删除;空“;?

2 个回复
最合适的回答,由SO网友:gimsech 整理而成

我解决了它。看来空值是通过$args.

            <?php wp_list_categories( array(
   \'child_of\'            => 0,
    \'depth\'               => 0,
    \'echo\'                => 1,
    \'exclude\'             => \'\',
    \'exclude_tree\'        => \'\',
    \'feed\'                => \'\',
    \'feed_image\'          => \'\',
    \'feed_type\'           => \'\',
    \'hide_empty\'          => 0,
    \'hide_title_if_empty\' => 1,
    \'hierarchical\'        => 0,
    \'order\'               => \'ASC\',
    \'orderby\'             => \'title\',
    \'separator\'           => \' \',
    \'show_count\'          => 0,
    \'show_option_all\'     => \'A – Z | \',
    \'style\'               => 0,
    \'taxonomy\'            => \'category\',
    \'use_desc_for_title\'  => 1
    ) ); ?>

SO网友:Greg36

作用wp_list_categories 有一个论点echo 设置为1(true)。如果设置为true,则函数将输出内容,而不是返回值。因为什么都没有归还var_dump 显示空值。

更改echo 要返回值,请在参数数组中设置为false。

相关推荐

修改wp_Dropdown_Categories的输出以向每个选项添加术语ID

我一直在搜索关于如何修改wp\\u dropdown\\u categories的输出的文档或示例,以便我可以将术语ID添加到每个选项中。这可能吗?如果不是这样,我唯一的想法就是尝试使用jQuery,它看起来不那么可靠,也不那么快。这是我当前的代码:<div class=\"location-cats-dropdown\"> <form id=\"location-category-select\" class=\"location-category-select\" m