【问题标题】:WordPress get single link to couple categoriesWordPress 获得指向几个类别的单个链接
【发布时间】:2016-11-01 19:18:21
【问题描述】:

我有一个小的类别树:

例如

-main (id: 10)

--firstSub (id: 14)

--secondSub (id: 15)

--thirdSub (id: 16)

我想要的是获得一个链接到几个子类别(例如链接到 ids:14 和 16)或链接到主类别排除一个子类别(id:10 -id:15)。我不知道如何解决这个问题。 Get_the_category() 仅适用于单个类别,get_the_terms() 不适用于类别数组。我正在寻找任何可能解决这个问题的方法,但我没有匹配到任何东西。

有什么办法吗?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    您需要运行一个自定义循环来执行此操作...

    1. 在您的主题中创建页面模板...
      https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/
    2. 在模板 cmets 添加循环之后...
      https://codex.wordpress.org/The_Loop#Using_the_Loop
    3. 根据需要添加类别参数,猫 ID 以逗号分隔,排除类别以减号为前缀...
      $query = new WP_Query( 'cat=10,-15' ); //Shows posts in category 10 not in 15
    4. 现在您查询到了正确的帖子,只需使用帖子模板标签(或帖子模板部分,如果您的主题有它)即可根据需要输出帖子。
      https://codex.wordpress.org/Template_Tags#Post_tags

    【讨论】:

      猜你喜欢
      • 2022-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多