Answer the question
In order to leave comments, you need to log in
How to display article tags on a Wordpress category page?
You need to display a list of tags, under each of them - a list of articles that have this tag. I have all articles displayed under all tags.
function wph_alltags_shortcode($atts, $content) {
$posttags = get_tags();
if($posttags) {
foreach($posttags as $tag) {
$output.='<div class="category info"><div class="category-name">'.$tag->name.'</div> ';
$args = array(
'post_type' => 'info',
'publish' => true,
'paged' => get_query_var('paged'),
);
$output.='<div class="owl-carousel owl-theme">';
$image_id = get_post_thumbnail_id();
$the_query = new WP_Query( $args );
while ($the_query->have_posts() ) : $the_query->the_post();
$output.='<div class="item"><a href="'.get_permalink().'">'.get_the_post_thumbnail( $image_id,'large' ).'<div class="name">'.get_the_title().'</div></a></div>';
endwhile;
$output.='</div>';
wp_reset_postdata();
$output.='</div>';
}
}
return $output;
}
add_shortcode('alltags', 'wph_alltags_shortcode');
Answer the question
In order to leave comments, you need to log in
You need to add a value to the args array with something like the following content:
'tax_query' => array(
array(
'taxonomy' => 'taxonomyName',
'field' => 'id',
'terms' => $tag->term_id
)
)
function wph_alltags_shortcode($atts, $content) {
$posttags = get_tags();
if($posttags) {
foreach($posttags as $tag) {
$output.='<div class="category info"><div class="category-name">'.$tag->name.'</div> ';
$args = array(
'post_type' => 'info',
'publish' => true,
'paged' => get_query_var('paged'),
'tax_query' => array(
array(
'taxonomy' => 'taxonomyName',
'field' => 'id',
'terms' => $tag->term_id
)
)
);
$output.='<div class="owl-carousel owl-theme">';
$image_id = get_post_thumbnail_id();
$the_query = new WP_Query( $args );
while ($the_query->have_posts() ) : $the_query->the_post();
$output.='<div class="item"><a href="'.get_permalink().'">'.get_the_post_thumbnail( $image_id,'large' ).'<div class="name">'.get_the_title().'</div></a></div>';
endwhile;
$output.='</div>';
wp_reset_postdata();
$output.='</div>';
}
}
return $output;
}
add_shortcode('alltags', 'wph_alltags_shortcode');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question