drjk87189 2017-04-26 15:39
浏览 58

自定义分类法在变量中有连字符。 我怎么能回应呢?

New php guy here, so I apologize if I'm using the wrong words or terminology.

I'm working on an old site that has a custom WordPress taxonomy:

register_taxonomy('user-categories',array('user-posts'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'user-categories' ),
  ));

This custom taxonomy has a hyphen instead of an underscore in its name. So that means when I try to echo it the hyphen prevents me from referencing it properly like here:

echo '<li><i class="icon-heart"></i> '.$user-categories.'</li>';

In Coda 2 the hyphen turns blue and the word "categories" stops being purple (yes, I know I sound like a complete noob right now). I've looked around the net for a way to get the echo line to work, but everything I've tried has returned nothing.

Please help! Thank you!

  • 写回答

1条回答 默认 最新

  • douluanji8752 2017-04-26 15:48
    关注

    You can use something like

    $user_category = get_term_by('slug', 'user-categories', 'user-categories')
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用