WordPress 自定义分类法

发布于 2024-11-15 09:35:50 字数 1093 浏览 9 评论 0原文

我想知道是否有一种方法可以列出与当前页面同级的所有自定义分类法(例如在我的 single.php 中)?

例如,我的分类如下

类别

  • -- 古代
  • +++ 希腊
  • ///// 柏拉图
  • ///// 苏格拉底
  • +++ 罗马
  • +++ 印度
  • -- 经典
  • -- 现代

我想创建一个侧边栏列出具有相同父项的所有其他项目(包括其他兄弟姐妹的后代 - 例如“希腊”页面将列出“罗马”和“印度”。“古代”页面将包括指向“古代>>希腊”、“古代>>罗马”、“古代印度”、“经典”和“现代”页面。)

这可以通过自定义分类法实现吗?我怎样才能实现它?

谢谢!

*编辑*

另外,作为参考,我正在处理以下博客文章,这些文章可以更详细地了解我需要的内容,我只是在将其自定义为我在原来的帖子中提到的规范:

http://net.tutsplus.com/tutorials/wordpress/introducing-wordpress-3-custom-taxonomies/

https://github.com/scribu/wp-query-multiple-taxonomies/wiki/Changing-templates

http://scribu.net/wordpress/extending-the-category-walker.html

I'm wondering if there's a way to list all custom taxonomies that are siblings to the current page (e.g. in my single.php)?

For example my taxonomy is as follows

Categories

  • -- Ancient
  • +++ Greek
  • ///// Plato
  • ///// Socrates
  • +++ Roman
  • +++ Indian
  • -- Classic
  • -- Modern

I'd like to create a sidebar that lists all other items that have the same parent (including descendants of other siblings - e.g. "Greek" page would list "Roman" and "Indian". The "Ancient" page would include links to "Ancient >> Greek", "Ancient >> Roman", "Ancient >> Indian", "Classic" and "Modern" Pages. )

Is this possible with custom taxonomies? How can I achieve it?

Thanks!

*EDIT*

Also, for reference, I am working with the following blog posts which give a more detailed insight into what I need, I simply am having trouble customizing it to the specifications I mentioned in my original post:

http://net.tutsplus.com/tutorials/wordpress/introducing-wordpress-3-custom-taxonomies/

https://github.com/scribu/wp-query-multiple-taxonomies/wiki/Changing-templates

http://scribu.net/wordpress/extending-the-category-walker.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风启觞 2024-11-22 09:35:50
$post = get_post($id); //Get the post id

    if($post->post_parent){ //If it has a parent

        wp_list_pages('child_of='.$post->post_parent . '&exclude='.$id); //List the pages that are children of the parent page, excluding the current one.

    }

这将创建一个页面的所有同级页面的列表。我有一种感觉,您想要一些稍微不同的东西,正如您提到的自定义分类法和页面一样。这些是自定义帖子类型、类别还是页面?让我知道这是否适合您:)

$post = get_post($id); //Get the post id

    if($post->post_parent){ //If it has a parent

        wp_list_pages('child_of='.$post->post_parent . '&exclude='.$id); //List the pages that are children of the parent page, excluding the current one.

    }

This will create a list of all the siblings of a page. I have a feeling you want something slightly different, as you mention custom taxonomies as well as pages. Are these custom post types, categories, or pages? Let me know if this works for you :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文