I have a taxonomy called "country" and I need to visualize it as a list of categories can someone help me?
<li><a href="<?php echo esc_url( home_url() ); ?>/country/argentina/">Argentina</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/australia/">Australia </a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/canada/">Canada</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/china/">China</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/france/">France</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/germany/">Germany</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/india/">India</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/italy/">Italy</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/spain/">Spain</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/south-korea/">Korea</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/uk/">United Kingdom</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/usa/">USA</a></li>
I have a taxonomy called "country" and I need to visualize it as a list of categories can someone help me?
<li><a href="<?php echo esc_url( home_url() ); ?>/country/argentina/">Argentina</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/australia/">Australia </a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/canada/">Canada</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/china/">China</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/france/">France</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/germany/">Germany</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/india/">India</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/italy/">Italy</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/spain/">Spain</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/south-korea/">Korea</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/uk/">United Kingdom</a></li>
<li><a href="<?php echo esc_url( home_url() ); ?>/country/usa/">USA</a></li>
Share
Improve this question
asked Jul 1, 2020 at 8:31
Vincenzo PiromalliVincenzo Piromalli
1989 bronze badges
1
- Hi Vincenzo! So you want to create output like this from your taxonomy? Do you want to write code to do this and add it to your theme? What have you tried so far? – mozboz Commented Jul 1, 2020 at 10:02
1 Answer
Reset to default 1You can achieve the result using following code:
$terms = get_terms( array(
'taxonomy' => 'country',
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC',
) );
if ( !empty($terms) ) :
$output = '<ul>';
foreach( $terms as $country ) {
$output.= '<li><a href="'.get_term_link( $country->term_id ).'">'. esc_attr( $country->name ) .'</a></li>';
}
$output.='</ul>';
echo $output;
endif;
Here I'm using get_terms()
to get all item of country
taxonomy. The checking if there is any item in the list. If yes then I'm looping through them and returning as desired link. get_term_link()
is being used to get the term url by using term id.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742302375a4418268.html
评论列表(0条)