为城市创建自定义分类法,然后使用get_the_terms()
在图像URL中显示术语slug。
可供替代的
如果您只想要最后一个slug,那么可以使用PHP。将此放置在文件的最顶部get_header()
:
<?php
/* Grab the link. */
$link = $_SERVER[\'PHP_SELF\'];
/* Separate the url. */
$array = explode( \'/\', $link );
/* Count your way backwards. */
$last_slug = count( $array ) - 2;
$the_city = $array[$last_slug];
?>
OR
<?php
/* Grab the link. */
$link = $_SERVER[\'REQUEST_URI\'];
/* Separate the url. */
$array = explode( \'/\', $link );
/* Grab the second to last element in the array. */
$the_city = prev( $array );
?>
USAGE: Use the following for your image tag:
<img src="<?php echo bloginfo(\'url\'); ?>/wp-content/uploads/cities/<?php echo $the_city; ?>-140x140.jpg" alt=" " />