wordpress输出文章别名post_name

<?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

本文链接: https://www.168itw.com/wordpress/echo-post-name/
转载请注明转载自:168itw

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注