doolo00026
2015-06-29 02:40
浏览 59
已采纳

如何在Wordpress中使用类别slug url?

I'm in designing a WP Theme. I need help! I'm calling category and it's slug from plugin functions. Here is the code:

$category = get_the_category();
$html .= '<div id="category-post" class="category-main category'. $category[0]->slug .'">';
$html .= $category[0]->cat_name;
$html .= '</div>';

Let's say I have a class name for health category: .category-health

but the above code will returned to: <div id="category-post" class="category-main categoryhealth"></div> and the class: .category-health not working because it returned to unavailable category: .categoryhealth

From above code I feel that the category slug " - " is not working. Because the right class is ".category-health" and not ".categoryhealth"

Is there any way to fix this? Thanks

图片转代码服务由CSDN问答提供 功能建议

我正在设计WP主题。 我需要帮助! 我正在调用类别,它是插件函数的slu .. 以下是代码:

  $ category = get_the_category(); 
 $ html。='&lt; div id =“category-post”class =“category-main category  '。$ category [0]  - &gt; slug。'“&gt;'; 
 $ html。= $ category [0]  - &gt; cat_name; 
 $ html。='&lt; / div&gt;'; 
    
 
 

假设我有一个健康类别的类名:.category-health

但上面的代码将返回到:< 代码>&lt; div id =“category-post”class =“category-main categoryhealth”&gt;&lt; / div&gt; 和类:.category-health无法正常工作,因为它返回到不可用的类别:.categoryhealth

从上面的代码我觉得类别slug“ - ”不起作用。 因为正确的类是“.category-health”而不是“.categoryhealth”

有没有办法解决这个问题? 谢谢

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • donmqryh49993 2015-06-29 05:00
    已采纳

    Maybe it will help some one else with this answer. The right code is:

    $category = get_the_category();
    $html .= '<div id="category-post" class="category-main category-'. $category[0]->slug .'">';
    $html .= $category[0]->cat_name;
    $html .= '</div>';
    

    I just add - after category, category-main category–. almost like Nilambar said.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题