如何从 WordPress 中的帖子中获取 post slug? [英] How to get post slug from post in WordPress?

查看:23
本文介绍了如何从 WordPress 中的帖子中获取 post slug?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 http://example.com/project_name/abc_15_11_02_3/.我该怎么做?

I want to get "abc_15_11_02_3" from http://example.com/project_name/abc_15_11_02_3/. How can i do this?

推荐答案

您可以使用以下方法获得:

You can get that using the following methods:

<?php $post_slug = get_post_field( 'post_name', get_post() ); ?>

或者你可以使用这个简单的代码:

Or You can use this easy code:

<?php
    global $post;
    $post_slug = $post->post_name;
?>

这篇关于如何从 WordPress 中的帖子中获取 post slug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆