Show list of posts only on category site
I used the following code to create a list of my custom categories and custom post types:
<ul>
<?php
$custom_terms = get_terms('project_category', 'hide_empty=0');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'project',
'tax_query' => array(
array(
'taxonomy' => 'project_category',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<a href="'.get_permalink().'">'.$custom_term->name.'</a>';
while($loop->have_posts()) : $loop->the_post();
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
endwhile;
}
}
?>
</ul>
What I want to do is to hide the created anchors inside the list and only show them if the parent category is chosen. So I guess I should display them on the category site, and link the list items to the category site.
Can anyone give me a hint please?
I used the following code to create a list of my custom categories and custom post types:
<ul>
<?php
$custom_terms = get_terms('project_category', 'hide_empty=0');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'project',
'tax_query' => array(
array(
'taxonomy' => 'project_category',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<a href="'.get_permalink().'">'.$custom_term->name.'</a>';
while($loop->have_posts()) : $loop->the_post();
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
endwhile;
}
}
?>
</ul>
What I want to do is to hide the created anchors inside the list and only show them if the parent category is chosen. So I guess I should display them on the category site, and link the list items to the category site.
Can anyone give me a hint please?
No comments:
Post a Comment