<?php global $post; $post_slug = $post->post_name; ?>
输出:
<?php echo $post_slug; ?>
或者直接用:
<?php global $post; $post_slug=$post->post_name; echo $post_slug; ?>
另外一种方法是:
<?php $post_slug = get_post_field( 'post_name', get_post() ); ?>
进一步,如果要输出自定义字段的值,可以用:
<?php echo get_post_meta(get_the_ID(), 'key1', true); ?>
延伸:
wordpress常用函数:https://codex.wordpress.org/Function_Reference
wordpress全局变量:https://codex.wordpress.org/Global_Variables