我有一个自定义的帖子类型,例如,产品。它们可以是多层次的,比如页面,f.e。,
Products (custom post type)
Books
|- LOTR
|- Sherlock Holmes
|- Cooking help
|- etc
CD
|- Iron maiden
|- AC/DC
|- Brainstorm
|- etc
Manuals
|- MS Word manual
|- MS Excel manual
|- PHP manual
我需要一个层次(书籍,CD,手册)的第一级,我可以通过创建一个文件归档产品实现单独的页面。然后使用参数进行新的查询,以仅获取第一级。问题在于第二级。我不知道如何创建一个模板文件来显示电子书的子元素?
当然,我可以使用jquery来管理它。获取所有级别的层次结构,然后隐藏第二级,单击第一级名称,打开子级并隐藏第一级,但这不是我需要实现的解决方案,因为缺少正确的url。我想获得1级www.ddd的正确url。com/products/和www.ddd。com/产品/书籍/
您将如何实现这一点?
已更新
这是我的存档POSTTYPE中的内容。php文件。
<?php get_header();?>
<div id="maincol">
<?
$query = new WP_Query( \'post_type=produkts&post_parent=0\' );
while( $query->have_posts() ) : $query->the_post();
echo \'<li>\';
the_title();
echo \'</li>\';
endwhile;
wp_reset_postdata();
?>
</div>
<?php get_footer();?>
和单个posttype。php<?php get_header();?>
<div id="maincol">
<?php
if (is_child_post()){
//this is the true single product
the_title();
}else{
//this is the product list of parent
$query = new WP_Query( \'post_type=produkts&post_parent=\'.$post->ID.\'\' );
while( $query->have_posts() ) : $query->the_post();
echo \'<li>\';
the_title();
echo \'</li>\';
endwhile;
wp_reset_postdata();
}
?>
</div>
<?php get_footer();?>