Hey allemaal,
Ik ben momenteel bezig om een menu te maken die alle categorieën, subcategorieën en posts van een custom post type inlaad. Het moet er als volgt uit komen te zien:
HOOFDCATEGORIE
--SUBCATEGORIE
----POSTS
HOOFDCATEGORIE
--SUBCATEGORIE
----POSTS
HOOFDCATEGORIE
--SUBCATEGORIE
----POSTS
Er zullen alleen artikelen geplaatst worden in de subcategorie, echter moet vooralsnog de hoofdcategorie wel getoond worden. Nu heb ik de volgende code uitgedacht :
<!-- WONINGBOUW -->
<?php
$parent_cat = 8;
$taxonomy = 'category';
$cat_children = get_term_children( $parent_cat, $taxonomy );
if ($cat_children) {
echo '<ul>';
echo '<li><p>Woningbouw</p>';
foreach($cat_children as $category) {
$args=array(
'cat' => $category,
'post_type' => 'project',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
$child_cat = get_category($category);
if ($child_cat) {
echo '<ul>';
echo '<li><p>' . $child_cat->name . '</p>';
}
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<ul>
<li><p><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></p></li>
</ul>
<?php
endwhile;
} // if
echo '</li>';
echo '</ul>';
} // foreach
echo '</ul>';
} // cat_child
wp_reset_query(); // Restore global
?>
Toon Meer
Nu laad hij alleen de volgende structuur zien :
HOOFDCATEGORIE 1
SUBCATEGORIE 1
--POST 1
HOOFDCATEGORIE 1
--SUBCATEGORIE 1
----POST 1
SUBCATEGORIE 1
Verder laad hij nu ook niet automatisch de posts in, maar heb ik deze vooraf ingesteld. Dit is natuurlijk ook niet de bedoeling, maar ik wil eigenlijk eerst de structuur goed hebben.
Nu ben ik al een paar dagen flink aan het sleutelen aan dezelfde code en zie ik daarom door de bomen het bos niet meer... Maar heeft misschien iemand enig idee hoe ik dat kan oplossen? Het gaat om een zakelijk project, link gelieve via PM vragen.