php - get_the_terms issue on foreach loop -



php - get_the_terms issue on foreach loop -

i want show taxonomy name in post. utilize foreach loop not show thing me.

here code.

<?php global $post; $foo_home_url = site_url(); $url = "http://" . $_server['http_host'] . $_server['request_uri']; if(strpos($url, 'foo_cat')){ $foo_bc_cat = get_the_terms( $post->id , foo_post_taxonomy ); ?> <ul> <li><a href="<?php echo $foo_home_url; ?>">home</a></li> <?php foreach($foo_bc_cat $foo_tax_cat){ ?> <li><a href="<?php echo get_term_link($foo_tax_cat->slug, foo_post_taxonomy) ?>"><?php echo $foo_tax_cat->name ?></a></li> <?php } ?> </ul> <?php } ?>

any idea.

use code

<?php global $post; $foo_home_url = site_url(); $url = "http://" . $_server['http_host'] . $_server['request_uri']; if(strpos($url, 'foo_cat')){ $foo_bc_name = get_queried_object()->name; ?> <ul> <li><a href="<?php echo $foo_home_url; ?>">home</a></li> <li><a href="<?php echo get_term_link($foo_tax_cat->slug, foo_post_taxonomy) ?>"><?php echo $foo_bc_name; ?></a></li> </ul> <?php } ?>

instead of code

<?php global $post; $foo_home_url = site_url(); $url = "http://" . $_server['http_host'] . $_server['request_uri']; if(strpos($url, 'foo_cat')){ $foo_bc_cat = get_the_terms( $post->id , foo_post_taxonomy ); ?> <ul> <li><a href="<?php echo $foo_home_url; ?>">home</a></li> <?php foreach($foo_bc_cat $foo_tax_cat){ ?> <li><a href="<?php echo get_term_link($foo_tax_cat->slug, foo_post_taxonomy) ?>"><?php echo $foo_tax_cat->name ?></a></li> <?php } ?> </ul> <?php } ?>

php wordpress foreach

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -