【问题标题】:Get current category id for use in shortcode获取当前类别 ID 以在短代码中使用
【发布时间】:2013-12-23 17:02:18
【问题描述】:

我需要获取当前类别 ID 以在短代码中使用,我正在尝试但错误。

$category_current = get_the_category($post->ID) ; echo do_shortcode('[dt-postwall    postwalltype="masonry" category="'.get_the_category($post->ID).'"]

可以帮助我吗?谢谢

【问题讨论】:

    标签: wordpress categories shortcode


    【解决方案1】:

    工作正常,但只显示第一张图片,我不知道为什么,当我禁用 category="'.$category_current[0]->name.'" 所有帖子都会显示

    【讨论】:

      【解决方案2】:

      get_the_category,返回类别对象数组。
      所以你需要做以下事情

      $category_current = get_the_category($post->ID) ; 
      echo do_shortcode('[dt-postwall    postwalltype="masonry" category="'.$category_current[0]->name.'"]
      

      如果你想要分类 slug
      $category_current[0]->蛞蝓
      $category_current[0]->term_id

      【讨论】:

        猜你喜欢
        • 2011-07-27
        • 1970-01-01
        • 1970-01-01
        • 2012-02-08
        • 1970-01-01
        • 1970-01-01
        • 2016-03-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多