你可以在下面这样的事情中找到
add_shortcode( \'url_path_number\', function ( $atts ) {
// use an attribute or the current URL
$a = shortcode_atts( array(
\'url\' => get_permalink(),
), $atts );
// get the path from the URL
$path = parse_url($a[\'url\'],PHP_URL_PATH);
$parts = array_filter(explode(\'/\', $path),function($v) { return $v !== \'\'; });
// get the last dir of path
return end($parts);
} );
使用快捷码将返回当前URL
[url_path_number]
或者您可以指定URL
[url_path_number url="https://example.com/page/c/1"]
更新:只在路径之后,不使用
get_permalink()
add_shortcode( \'url_path_number\', function ( $atts ) {
$a = shortcode_atts( array(
\'path\' => $_SERVER[\'REQUEST_URI\'],
), $atts );
$parts = array_filter(explode(\'/\',$a[\'path\']),function($v) { return $v !== \'\'; });
return end($parts);
} );