【问题标题】:Can't display the category name wordpress无法显示类别名称 wordpress
【发布时间】:2018-05-04 13:03:57
【问题描述】:

我想在菜单(引导程序的导航栏)中显示类别名称。 这是我的代码:

<nav class="navbar navbar-expand navbar-light bg-light flex-md-column flex-row align-items-start py-3">
        <div class="collapse navbar-collapse">
                <ul class="flex-md-column flex-row navbar-nav w-100 justify-content-between">
                        <li class="nav-item">
                                    <a class="test1" href="#"><?php echo get_cat_name(4); ?></a>
                        </li>
                  </ul>
      </div>

什么都不显示,4 是我的“议程”类别的 ID。

感谢您的帮助。

【问题讨论】:

  • &lt;?php print_r(get_categories()); ?&gt; 使用这个并将结果发送给我
  • 感谢您的回答,它显示: > Array ( [7] => WP_Term Object ( [term_id] => 1 [name] => Non classé [slug] => non-classe [term_group ] => 0 [term_taxonomy_id] => 1 [taxonomy] => category [description] => [parent] => 0 [count] => 319 [filter] => raw [cat_ID] => 1 [category_count] => 319 [category_description] => [cat_name] => Non classé [category_nicename] => non-classe [category_parent] => 0 ) [8] => WP_Term Object ( [term_id] => 3 [name] => Offres d' emploi [slug] => offres-demploi [term_group] => 0 [term_taxonomy_id] => ...
  • 我不精确,但我想显示子类别名称,也许它不同?
  • 试试这个&lt;?php echo get_the_category_by_ID(4); ?&gt;
  • 我有这个:Catchable fatal error: Object of class WP_Error could not be convert to string in C:\xamp\htdocs\wordpress\wp-content\themes\child_theme\archive.php on line 43

标签: php html wordpress categories


【解决方案1】:
<nav class="navbar navbar-expand navbar-light bg-light flex-md-column flex-row align-items-start py-3">
        <div class="collapse navbar-collapse">
                <ul class="flex-md-column flex-row navbar-nav w-100 justify-content-between">
                        <li class="nav-item">
                                    <a class="test1" href="#"><?php echo get_the_category(4); ?></a>
                        </li>
                  </ul>
      </div>

【讨论】:

    猜你喜欢
    • 2010-09-23
    • 1970-01-01
    • 2015-01-01
    • 2013-09-03
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 2018-10-15
    • 2021-12-24
    相关资源
    最近更新 更多