I have a custom post type, for examle, products. They can be multilevel, like pages, 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
I need a seperate pages for first level of hierachy (Books, CD, manuals), what i can achieve by creating a file archive-products.php in theme directory and then making a new query with parameter to get only first level.
The problem is with the second level. I cannot figure out, how to create a template file for displaying a child elements of f.e. Books ?
Of course, i can manage it by using jquery. Get all level of hierarchy, then hide second level and on the click of first level Name, open sublevel and hide first level, but this is not a solution what i need to achieve, because of the lack of the correct url. I want to get correct url for 1 level www.ddd.com/products/ and also for the second www.ddd.com/products/books/
How would you accomplish this?
UPDATED
This is what I have in my archive-POSTTYPE.php file.
<?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();?>
and the single-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();?>